是否可以从代码进入ipython? [英] Is it possible to go into ipython from code?

查看:111
本文介绍了是否可以从代码进入ipython?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的调试需求, pdb 是相当不错的。但是,如果我可以进入 ipython ,那么它会更冷(更有帮助)。这个事情可能吗?

For my debugging needs, pdb is pretty good. However, it would be much cooler (and helpful) if I could go into ipython. Is this thing possible?

推荐答案

有一个 ipdb 项目嵌入iPython进入标准的pdb,所以你可以这样做:

There is an ipdb project which embeds iPython into the standard pdb, so you can just do:

import ipdb; ipdb.set_trace()

它可以通过通常的 pip install ipdb

ipdb 相当短,因此,您可以创建一个文件 ipdb.py 在Python路径的某处,并将以下内容粘贴到文件中:

ipdb is pretty short, so instead of easy_installing you can also create a file ipdb.py somewhere on your Python path and paste the following into the file:

import sys
from IPython.Debugger import Pdb
from IPython.Shell import IPShell
from IPython import ipapi

shell = IPShell(argv=[''])

def set_trace():
    ip = ipapi.get()
    def_colors = ip.options.colors
    Pdb(def_colors).set_trace(sys._getframe().f_back)

这篇关于是否可以从代码进入ipython?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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