简体   繁体   English

是否可以通过调试在IPython中运行命令?

[英]Is it possible to run commands in IPython with debugging?

Here are my actions in IPython: 以下是我在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. 我想在Graph.from_osm中放置一个断点,而不编辑文件。 I don't want to put the latter lines into the file and to do python -m ipdb ... . 我不想把后面的行放到文件中并做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 ! 但是不可能做ipdb.run('statement')ipdb没有.run

Since IPython 3.2.2 , the %debug magic, if given an argument (a single line or a cell), executes it under debugger. IPython 3.2.2%debug magic,如果给出一个参数(单行或单元格),则在调试器下执行它。

  • 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). 它接受一个设置一个断点的--breakpoint参数(作为命令的一部分,它将保存在命令历史记录中,为您节省重复调用的输入)。

也许IPython中的'magic'命令%debug和/或%pdb可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM