是否可以通过调试在IPython中运行命令? [英] Is it possible to run commands in IPython with debugging?

查看:105
本文介绍了是否可以通过调试在IPython中运行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我在IPython中的行为:

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)

我想在Graph.from_osm中放置一个断点,而不编辑文件。我不想将后面的行放入文件中并执行 python -m ipdb ... 。我只是想运行命令和调试。

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.

这可能吗?

已添加:我知道,有可能

%run -d script_name

> import pdb
> pdb.run('statement')

但是不可能做 ipdb。 run('statement') ipdb 中没有 .run

but it's impossible to do ipdb.run('statement'), there's no .run in ipdb!

推荐答案

由于 IPython 3.2.2 %debug magic,如果给出一个参数(单行或一个单元格),在调试器下执行它。

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).

这篇关于是否可以通过调试在IPython中运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆