PDB中的自动完成和Tab键

Rod*_*pez 16 python python-2.7 pdb

TAB在(pdb)提示符下,我一直试图做一些其他事情而不是插入标签.

我想到的是触发自动完成,例如在这里这里,但tab键除了向pdb添加选项卡之外没有做任何其他事情.

所以:

(pdb)var + tabKeyPressed

我想得到:

(pdb)variable

代替:

(pdb)var[          ]

PAD*_*MKO 13

iPython是解决此问题的第三方解决方案.有时你只能依靠vanilla Python.我找到了2个解决方案.

每shell解决方案 - 使用模块'rlcompleter':

$ python3

Python 3.4.3 (default, Sep 14 2016, 12:36:27) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import pdb
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None

# press tab - but nothing
(Pdb) str.
*** SyntaxError: invalid syntax
(Pdb) --KeyboardInterrupt--
(Pdb) c
>>> import rlcompleter
>>> pdb.Pdb.complete=rlcompleter.Completer(locals()).complete
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) str.
str.__add__(            str.__getattribute__(   str.__name__            str.__text_signature__  str.isdigit(            str.rfind(
str.__base__(           str.__getitem__(        str.__ne__(             str.__weakrefoffset__   str.isidentifier(       str.rindex(
str.__bases__           str.__getnewargs__(     str.__new__(            str.capitalize(         str.islower(            str.rjust(
str.__basicsize__       str.__gt__(             str.__prepare__(        str.casefold(           str.isnumeric(          str.rpartition(
str.__call__(           str.__hash__(           str.__qualname__        str.center(             str.isprintable(        str.rsplit(
str.__class__(          str.__init__(           str.__reduce__(         str.count(              str.isspace(            str.rstrip(
str.__contains__(       str.__instancecheck__(  str.__reduce_ex__(      str.encode(             str.istitle(            str.split(
str.__delattr__(        str.__itemsize__        str.__repr__(           str.endswith(           str.isupper(            str.splitlines(
str.__dict__            str.__iter__(           str.__rmod__(           str.expandtabs(         str.join(               str.startswith(
str.__dictoffset__      str.__le__(             str.__rmul__(           str.find(               str.ljust(              str.strip(
str.__dir__(            str.__len__(            str.__setattr__(        str.format(             str.lower(              str.swapcase(
str.__doc__             str.__lt__(             str.__sizeof__(         str.format_map(         str.lstrip(             str.title(
str.__eq__(             str.__mod__(            str.__str__(            str.index(              str.maketrans(          str.translate(
str.__flags__           str.__module__          str.__subclasscheck__(  str.isalnum(            str.mro(                str.upper(
str.__format__(         str.__mro__             str.__subclasses__(     str.isalpha(            str.partition(          str.zfill(
str.__ge__(             str.__mul__(            str.__subclasshook__(   str.isdecimal(          str.replace(            
(Pdb) c
>>>
Run Code Online (Sandbox Code Playgroud)

系统范围的解决方案 - 使用文件〜/ .pdbrc

$ cat ~/.pdbrc
import rlcompleter
pdb.Pdb.complete=rlcompleter.Completer(locals()).complete
$ python3
Python 3.4.3 (default, Sep 14 2016, 12:36:27) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) str.
str.__add__(            str.__getattribute__(   str.__name__            str.__text_signature__  str.isdigit(            str.rfind(
str.__base__(           str.__getitem__(        str.__ne__(             str.__weakrefoffset__   str.isidentifier(       str.rindex(
str.__bases__           str.__getnewargs__(     str.__new__(            str.capitalize(         str.islower(            str.rjust(
str.__basicsize__       str.__gt__(             str.__prepare__(        str.casefold(           str.isnumeric(          str.rpartition(
str.__call__(           str.__hash__(           str.__qualname__        str.center(             str.isprintable(        str.rsplit(
str.__class__(          str.__init__(           str.__reduce__(         str.count(              str.isspace(            str.rstrip(
str.__contains__(       str.__instancecheck__(  str.__reduce_ex__(      str.encode(             str.istitle(            str.split(
str.__delattr__(        str.__itemsize__        str.__repr__(           str.endswith(           str.isupper(            str.splitlines(
str.__dict__            str.__iter__(           str.__rmod__(           str.expandtabs(         str.join(               str.startswith(
str.__dictoffset__      str.__le__(             str.__rmul__(           str.find(               str.ljust(              str.strip(
str.__dir__(            str.__len__(            str.__setattr__(        str.format(             str.lower(              str.swapcase(
str.__doc__             str.__lt__(             str.__sizeof__(         str.format_map(         str.lstrip(             str.title(
str.__eq__(             str.__mod__(            str.__str__(            str.index(              str.maketrans(          str.translate(
str.__flags__           str.__module__          str.__subclasscheck__(  str.isalnum(            str.mro(                str.upper(
str.__format__(         str.__mro__             str.__subclasses__(     str.isalpha(            str.partition(          str.zfill(
str.__ge__(             str.__mul__(            str.__subclasshook__(   str.isdecimal(          str.replace(            
(Pdb) c
>>> 
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. 仅在Python 3.4上测试过

  2. 操作系统 - Linux Mint

  3. 基于https://reminiscential.wordpress.com/2009/06/12/python-enable-auto-complete-in-a-pdb-session/

  • 要使用“python -m pdb script.py”调用 pdb,您还应该在“.pdbrc”中“import pdb”。 (2认同)

esh*_*han 11

官方文件称:

版本 3.3 中的更改:通过 readline 模块进行制表符补全可用于命令和命令参数,例如,当前全局和本地名称作为 p 命令的参数提供。

https://docs.python.org/3/library/pdb.html

所以你只需使用p命令:

(Pdb) p var[TAB] # complete global and local names
var1 var2
(Pdb) [TAB] # complete commands
EOF        b          cl         cont       disable    exit       interact   list       next       quit       retval     source     unalias    up         
a          break      clear      continue   display    h          j          ll         p          r          run        step       undisplay  w          
alias      bt         commands   d          down       help       jump       longlist   pp         restart    rv         tbreak     unt        whatis     
args       c          condition  debug      enable     ignore     l          n          q          return     s          u          until      where 
Run Code Online (Sandbox Code Playgroud)


shx*_*hx2 9

ipdb来救援.

ipdb导出函数来访问IPython调试器,它具有 选项卡完成,语法突出显示,更好的回溯,更好的内省,与pdb模块相同的接口.

  • 我确实尝试了一段时间,它确实提供了货物.我不是很喜欢它. (2认同)