gpt4 book ai didi

python - 在 ipdb shell 中使用 IPython 魔术函数

转载 作者:IT老高 更新时间:2023-10-28 20:46:29 24 4
gpt4 key购买 nike

在使用ipdb my_script.py调试Python脚本时,我想在中使用%paste%cd等IPython魔术函数>ipdb 调试 session 外壳。是否有可能以及如何?

最佳答案

根据ipdb Github repo魔术 IPython 函数不可用。幸运的是,IPython debugger提供了一些关于如何在不启动单独的 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

这样,您可以通过 find_line_magic(your_magic_function) 方法单步执行代码并访问所有 IPython 魔术函数。

关于python - 在 ipdb shell 中使用 IPython 魔术函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16184487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com