How to define a new function in pdb

Viewed 2751

Why can't I define new functions when I run pdb?

For example take myscript.py:

#!/gpfs0/export/opt/anaconda-2.3.0/bin/python
print "Hello World"
print "I see you"

If I run python -m pdb myscript.py and try to interactively define a new function:

def foo():

I get the error:

*** SyntaxError: unexpected EOF while parsing (<stdin>, line 1)

Why is this?

4 Answers

If your application happens to have IPython as a dependency, you could drop yourself into a feature-rich IPython REPL right from ipdb:

import IPython; IPython.embed()

From inside, if you run IPython's magic command whos, you should see all the locally defined variables in the current pdb frame.

Related