iPython是用于解决这个问题的第三方解决方案。有时您只能依赖原始的Python。我找到了2种解决方案。
对于每个终端的解决方案-使用“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
>>>
系统范围解决方案 - 使用文件 ~/.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
>>>
注意:
仅在Python 3.4上进行过测试
操作系统 - Linux Mint
基于https://reminiscential.wordpress.com/2009/06/12/python-enable-auto-complete-in-a-pdb-session/
python -m pdb script.py
调用 pdb,您还应该在 .pdbrc
中导入 pdb
。 - jdhaopip install gnureadline
。 - tharndttabKeyPressed
实际上会将焦点移动到下一个单元格,这有意义吗?(例如,如果我使用%%debug
)-谢谢! - jjrripdb 来解救你。
ipdb 导出函数以访问 IPython 调试器,具有制表符完成、语法高亮、更好的回溯、更好的内省功能,与 pdb 模块相同的接口。
官方文件指出:
自版本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
Pdb
的p
命令,基本上用于相同的用例,您将获得自动完成。 - YuvalHelman~/.editrc
中加入这个 python:bind "\011" rl_complete
。我已经更新了我的 Python PR(https://github.com/python/cpython/pull/107748#issuecomment-1668593509)。 - undefined