How to define a new function in pdb

萝らか妹 提交于 2019-11-30 12:17:45

You can define your function in a one line statement using ; instead of indentation, like this:

(Pdb) def foo(): print 'Hello world'; print 'I see you'
(Pdb) foo()
Hello world
I see you

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

i was able to import python modules from the pdb command line.

if you can import python modules, then you should be able to define your functions in a file and just do an import of the file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!