Monday, 25 June 2012

Debugging Python scripts

Here are some tips to debugging python scripts:

1) Starting the debugger:

python -m pdb <<script>>

2) Useful commands:
Execute the current line, stop at the first possible occasion (either in a function that is called or on the next line in the current function).
Continue execution until the next line in the current function is reached or it returns. (The difference between next and step is that step stops inside a called function, while next executes called functions at (nearly) full speed, only stopping at the next line in the current function.)
p expression
Evaluate the expression in the current context and print its value.

(Pdb) ?

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

Miscellaneous help topics:
exec  pdb

Undocumented commands:
retval  rv

List all the available parameters or functions of an object.

No comments:

Post a Comment