Is it possible to run commands in IPython with debugging?

时光毁灭记忆、已成空白 提交于 2020-01-03 07:25:09

问题


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!


回答1:


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 the typing for repeated invocations).



回答2:


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



来源:https://stackoverflow.com/questions/9689378/is-it-possible-to-run-commands-in-ipython-with-debugging

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