我有 IPython(0.13.1)
和 ipdb(0.7)
安装后,我插入了 import ipdb;ipdb.set_trace()
行在我的脚本中运行 python my_script.py
.现在我在 ipdb 提示符下,有一些自动完成(例如,一个裸标签),但它与我输入 IPython 时得到的自动完成不同。在 ipdb 提示符 requests.
然后 <tab>
(导入后)没有像 IPython 那样给我一个属性列表。如何使用 ipdb 获得与在 IPython 中相同的选项卡完成?
顺便说一句,当我运行 python -m ipdb my_script.py
时制表符补全的工作方式与 IPython 中一样,但它的缺点是它从第一行而不是我放置的行启动调试器 import ipdb;ipdb.set_trace()
.
最佳答案
我在我的 Mac 上使用 ipython==0.13.2
和 ipdb==0.7
在 Python 2.7.5
中遇到了同样的现象虚拟环境。当我尝试调试时,我有内置的选项卡完成,但不是当前范围内的变量。我发现,我的主文件夹 (http://docs.python.org/2/library/pdb.html#id2) 中有一个自定义 .pdbrc
。在我把所有的东西都注释掉之后,标签补全又起作用了。
我不知道我何时以及为什么添加了这个文件,但这就是其中的内容:
# 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)
需要进一步的研究来检查是什么破坏了那里的制表符完成......
关于python - 获取 ipdb 的 IPython 选项卡完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15122375/