How to define a new function in pdb
Question: 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?


Answer: I don't think it supports multi-line input. You can workaround by spawning up
an interactive session from within pdb. Once you are done in the interactive
session, exit it with Ctrl+D.

    
    
    >>> import pdb
    >>> pdb.set_trace()
    (Pdb) !import code; code.interact(local=vars())
    (InteractiveConsole)
    In : def foo():
    ...:     print 'hello in pdb'
    ...: 
    In : # use ctrl+d here to return to pdb shell...
    (Pdb) foo()
    hello in pdb
    

