以下是我在IPython中的行为:
> import my_module
> import ipdb
Run Code Online (Sandbox Code Playgroud)
现在,我的模块缺少任何可执行代码,它只声明类.所以我想发表一个声明:
> g = my_module.Graph()
> f = open('test.osm')
> g.from_osm(f)
Run Code Online (Sandbox Code Playgroud)
我想在Graph.from_osm中放置一个断点,而不编辑文件.我不想把后面的行放到文件中去做python -m ipdb ....我只想运行命令和调试.
这可能吗?
补充:我明白了,有可能
%run -d script_name
Run Code Online (Sandbox Code Playgroud)
要么
> import pdb
> pdb.run('statement')
Run Code Online (Sandbox Code Playgroud)
但它是不可能做ipdb.run('statement'),有没有.run在ipdb!
我刚开始使用漂亮的PyCharm社区版IDE,并且不能做一个简单的事情,这是我常用的Python工作流程的一部分.
我已经启动了一个ipython控制台,我可以导入我的模块并以交互方式运行命令.在PyCharm中,当我执行一个函数调用时,它就像在一个单独的进程中运行一样执行.即使在执行完成之前,也可以使用控制台提示符.在PyCharm外部的shell中运行ipython,当发生异常时,我可以运行pdb的post mortem功能并调查问题:
import pdb;pdb.pm()
Run Code Online (Sandbox Code Playgroud)
我想在PyCharm中做同样的事情:当我在交互式调查问题时发生异常时,开始事后调试.
如何在我的代码中嵌入一个IPython shell并让它自动显示调用它的行号和函数?
我目前有以下设置在我的代码中嵌入IPython shell:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
from IPython.config.loader import Config
# Configure the prompt so that I know I am in a nested (embedded) shell
cfg = Config()
prompt_config = cfg.PromptManager
prompt_config.in_template = 'N.In <\\#>: '
prompt_config.in2_template = ' .\\D.: '
prompt_config.out_template = 'N.Out<\\#>: '
# Messages displayed when I drop into and exit the shell.
banner_msg = ("\n**Nested Interpreter:\n"
"Hit Ctrl-D to exit interpreter and continue program.\n"
"Note that if you …Run Code Online (Sandbox Code Playgroud)