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
pyflakes
can do source code checkingmypy
can 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 linting
and 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) time
is the time elapsed in real world (The time you need to wait before you get your result)cpu time
is the time your program occupy the CPU (relating to scheduling algorithm)user time
is time spent executing user-level codesystem time
is time spent executing kernal-level code
Tools
kernprof
gives time-cost line by lineperf
(really powerful !)lsof
find more at notes