19

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!

2
  • 1
    There is a .run in ipdb 0.8. Commented Apr 4, 2014 at 13:00
  • 1
    possible duplicate of Stepping into a function in IPython Commented Mar 5, 2015 at 17:20

2 Answers 2

8

Since IPython 3.2.2, the %debug magic, if given an argument (a single line or a cell), executes it under debugger.

  • It breaks before executing anything, giving you a chance to set breakpoints and/or start stepping through the code.
  • And it accepts a --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).
Sign up to request clarification or add additional context in comments.

Comments

2

Perhaps the 'magic' commands %debug and / or %pdb in IPython can help you.

3 Comments

No, it's not what I look for. They both stop at an exception. I just want to watch program execution step by step.
As of IPython 5, debug stops before executing anything, allowing you to set breakpoints and/or begin stepping through the code.
IPython 6 stops at exception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.