Debugging
pdb tutorial
(ipdb has a more friendly user interface)
list source code
1 | $ python3 -m pdb bar.py |
execute line by line
1 | pdb> s |
restart and continue
1 | pdb> restart |
1 | pdb> p varname |
Static analyze tools
pyflakescan do source code checkingmypycan do the same job
Most editors and IDEs support displaying the output of these tools within the editor itself, highlighting the locations of warnings and errors. This is often called
code lintingand it can also be used to display other types of issues such as stylistic violations or insecure constructs.
There are even tools for your English writing : writegood
Profiling
Time
1 | $ time sleep 3 |
total(real) timeis the time elapsed in real world (The time you need to wait before you get your result)cpu timeis the time your program occupy the CPU (relating to scheduling algorithm)user timeis time spent executing user-level codesystem timeis time spent executing kernal-level code
Tools
kernprofgives time-cost line by lineperf(really powerful !)lsof
find more at notes