获取ipdb的IPython选项卡完成 [英] Get IPython tab completion for ipdb

查看:130
本文介绍了获取ipdb的IPython选项卡完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 IPython(0.13.1) ipdb(0.7),我插入了行在我的脚本中导入ipdb; ipdb.set_trace()并运行 python my_script.py 。现在我在ipdb提示符下并且有一些自动完成(例如裸标签),但它与我进入IPython时获得的自动完成功能不同。在ipdb提示符 requests。然后< tab> (导入后)没有给我一个属性列表在IPython中。如何使用ipdb获得与IPython相同的选项卡完成?

I have IPython(0.13.1) and ipdb(0.7) installed, I inserted the line import ipdb;ipdb.set_trace() in my script and ran python my_script.py. Now I am in the ipdb prompt and there is some autocompletion (e.g. a bare tab) but it's not the same as the autocompletion I get when I enter IPython. In the ipdb prompt requests. then <tab> (after import) does not give me a list of attributes as in IPython. How do I get that same tab completion as in IPython with ipdb?

顺便说一下,当我运行 python -m ipdb my_script.py 标签完成的工作方式与IPython一样,但其缺点是它从第一行启动调试器而不是我放的行 import ipdb; ipdb.set_trace()

Btw, when I run python -m ipdb my_script.py the tab completion works just as in IPython but the downside of this is that it starts the debugger from the first line instead of the line I've put import ipdb;ipdb.set_trace().

推荐答案

我在Mac上使用 ipython发生了同样的现象== 0.13.2 ipdb == 0.7 Python 2.7.5 virtualenv中。当我尝试调试时,我有内置函数的选项卡完成,但不适用于当前范围中的变量。我发现,我的主文件夹中有一个自定义 .pdbrc http://docs.python.org/2/library/pdb.html#id2 )。在我评论完所有内容之后,标签完成再次起作用。

I had the same phenomenon on my Mac using ipython==0.13.2 and ipdb==0.7 inside a Python 2.7.5 virtualenv. When I tried to debug, I had the tab completion for the builtins, but not for the variables in the current scope. I discovered, that I had a custom .pdbrc located in my home folder (http://docs.python.org/2/library/pdb.html#id2). After I commented all the stuff out, the tab completion worked again.

我不知道何时以及为什么我添加了这个文件,但这就是那里的内容:

I don't know when and why I added this file, but this is what was in there:

# See http://docs.python.org/2/library/pdb.html#id2 for the structure of this file.
import pdb

# 'inspect x' will print the source code for a method, class or function.
alias inspect import inspect;print inspect.getsource(%1)
alias i import inspect;print inspect.getsource(%1)
# 'help x' opens the man-style help viewer from the interpretter on an object
alias help !print help(%1)
alias h !print help(%1)
# For ordinary Python objects, ppo will pretty-print members and their values.
alias ppo pp %1.__dict__
# ppio runs ppo over a sequence of objects
alias ppio pp [a.__dict__ for a in %1]

# This tries to enable tab-completion of some identifiers.
!import rlcompleter
!pdb.Pdb.complete = rlcompleter.Completer(locals()).complete

# Taken from https://gist.github.com/1125049
# There are a couple of edge cases where you can lose terminal
# echo. This should restore it next time you open a pdb.
!import termios, sys
!termios_fd = sys.stdin.fileno()
!termios_echo = termios.tcgetattr(termios_fd)
!termios_echo[3] = termios_echo[3] | termios.ECHO
!termios_result = termios.tcsetattr(termios_fd, termios.TCSADRAIN, termios_echo)

需要进一步的研究来检查那里的标签完成是什么......

Further research is needed to check what breaks the tab-completion in there...

这篇关于获取ipdb的IPython选项卡完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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