In case something does not work the way you want there are several ways to debug things.
Viewing module contents¶
We recommend to create a simple file with just the part that does not work.
We usually call this file
ex.py and remove it before the actual commit.
To reveal internals of this Python source code, you can use following options:
astboom < ex.pywill show you pretty-printed
tokelor ex.pywill show you pretty-printed token stream
It might not be enough to find some complex cases, but it helps.
A lot of people (including @sobolevn) finds test-driven development really useful to design and debug your code.
Write a single test that fails for your new feature or exposes a bug
Run it with
Use the magic of
ast.dumpto view the contents of nodes
Fix the bug or implement a new feature
Make sure that everything works now: tests must pass
We recommend to use
ipdb for interactive debugging
(it is already included as a development package to this project).
To start interactive debugging session you will need to:
export PYTHONBREAKPOINT=ipdb.set_traceenvironment variable
breakpoint()call in places where you need your debugger to stop
Run your program as usual, debugger will stop on places you marked
This way allows to view local variables, execute operations step by step, debug complex algorithms.
One can use
pycharm to visually debug your app.
In this case you need to setup appropriate entrypoints
and run your app in debug mode.