在ipdb shell中使用IPython魔术函数 [英] Use IPython magic functions in ipdb shell
问题描述
当使用 ipdb my_script.py
调试Python脚本时,我想使用IPython魔术函数,如%paste
调试会话shell在 ipdb
中的%cd
是可能的,如何?
When debugging Python script using ipdb my_script.py
, I want to use IPython magic functions like %paste
, %cd
in ipdb
debug session shell. Is is possible and how?
推荐答案
根据 ipdb Github repo 魔术IPython功能不可用。幸运的是, IPython调试器提供了几个关于如何获取的线索这个功能没有启动一个单独的IPython shell。
According to the ipdb Github repo magic IPython functions are not available. Fortunately, the IPython debugger provides a couple of clues of how to get this functionality without launching a separate IPython shell.
这是我执行的操作%cpaste
:
ipdb> from IPython import get_ipython
ipdb> shell = get_ipython()
ipdb> shell.find_line_magic('cpaste')()
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:for i in range(0,5):
: print i
:--
0
1
2
3
4
这样,您可以逐步浏览代码并访问所有IPython魔术通过方法 find_line_magic(your_magic_function)
。
This way, you can step through your code and have access to all the IPython magic functions via the method find_line_magic(your_magic_function)
.
这篇关于在ipdb shell中使用IPython魔术函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!