Here are my actions in IPython:
> import my_module
> import ipdb
Now, my module lacks any executable code, it only declares classes. So I want to make a statement:
> g = my_module.Graph()
> f = open('test.osm')
> g.from_osm(f)
I want to put a breakpoint inside Graph.from_osm, without editing the file. I don't want to put the latter lines into the file and to do python -m ipdb ...
. I just want to run commands and debug.
Is this possible?
added: I see, it's possible to
%run -d script_name
or
> import pdb
> pdb.run('statement')
but it's impossible to do ipdb.run('statement')
, there's no .run
in ipdb
!
IPython has another way to start a debugger. You don't need to modify the source code of any file as we did before. If you run the %run -d filename.py magic command, IPython will execute the filename.py file and put a breakpoint on the first line there. It's just as if you would put the import ipdb; ipdb.
If you want some code to be run at the beginning of every IPython session, the easiest way is to add Python (. py) or IPython (. ipy) scripts to your profile_default/startup/ directory. Files here will be executed as soon as the IPython shell is constructed, before any other code or scripts you have specified.
IPython bridges this gap, and gives you a syntax for executing shell commands directly from within the IPython terminal. The magic happens with the exclamation point: anything appearing after ! on a line will be executed not by the Python kernel, but by the system command-line.
Debug code in Jupyter notebooks The Jupyter Notebook Debugger tool window opens. Debugging is performed within a single code cell. However, if your code cell calls a function from any cell that has been already debugged, you can step into it. The related breakpoints will also work.
Since IPython 3.2.2
, the %debug
magic, if given an argument (a single line or a cell), executes it under debugger.
--breakpoint
argument that sets one more breakpoint (as a part of the command, it'll be saved in command history, saving you typing for repeated invocations).Perhaps the 'magic' commands %debug and / or %pdb in IPython can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With