2016-12-01 26 views
1

我想知道如何在pdb中使用debug命令?如何在pdb中使用debug命令(python)

(Pdb) help 

Documented commands (type help <topic>): 
======================================== 
EOF c   d  h   list  q  rv  undisplay 
a  cl   debug help  ll  quit  s  unt 
alias clear  disable ignore longlist r  source until 
args commands display interact n   restart step  up 
b  condition down  j   next  return tbreak w 
break cont  enable jump  p   retval u  whatis 
bt  continue exit  l   pp  run  unalias where 

Miscellaneous help topics: 
========================== 
pdb exec 
(Pdb) help debug 
debug code 
     Enter a recursive debugger that steps through the code 
     argument (which is an arbitrary expression or statement to be 
     executed in the current environment). 
(Pdb) debug print('hello') 
ENTERING RECURSIVE DEBUGGER 
> <string>(1)<module>()->None 
((Pdb)) n 
hello 
--Return-- 
> <string>(1)<module>()->None 
((Pdb)) n 
LEAVING RECURSIVE DEBUGGER 
(Pdb) 

回答

0

讓,你有一堆代碼。你把pdb,比如第3行。

在這種情況下,當你運行程序時,第1行和第2行會自動執行,你可以通過放入變量名看到結果,並且不執行第4行。

如果你想看到第3行的結果,你必須編寫你想看的結果代碼,或者你可以去下一行使用nc繼續這意味着退出調試模式。

+2

謝謝@Shaon,但我明白如何使用Python進行調試,但有一個命令「debug」(請參閱​​幫助命令),我不明白。你有一個如何使用'debug'命令的例子 –