我有特殊的 Python 补全技巧
2014 12 6 01:11 AM 2532次查看
受不了的人就用起 IPython、bpython 来了。可问题是装这些玩意得下载啊,如果只是临时用用,实在太不方便了。
还好 Python 自带了一个 rlcompleter 模块,几行代码就能解决这个问题。
以下是在 OS X 上测试的,Windows 可能没有自带 readline 模块,自己想法解决吧:
>>> import rlcompleter
>>> import readline
>>> readline.parse_and_bind('tab: complete')
>>> rl<TAB>completer.<TAB>
rlcompleter.Completer rlcompleter.__file__ rlcompleter.__new__( rlcompleter.__str__(
rlcompleter.__all__ rlcompleter.__format__( rlcompleter.__package__ rlcompleter.__subclasshook__(
rlcompleter.__builtin__ rlcompleter.__getattribute__( rlcompleter.__reduce__( rlcompleter.get_class_members(
rlcompleter.__class__( rlcompleter.__hash__( rlcompleter.__reduce_ex__( rlcompleter.readline
rlcompleter.__delattr__( rlcompleter.__init__( rlcompleter.__repr__(
rlcompleter.__dict__ rlcompleter.__main__ rlcompleter.__setattr__(
rlcompleter.__doc__ rlcompleter.__name__ rlcompleter.__sizeof__(
>>> completer = rl<TAB>completer.C<TAB>ompleter()
>>> completer.c<TAB>omplete('comp', 0)
'compile('
>>> completer.c<TAB>omplete('comp', 1)
'complex('
不过,即使没有 readline 模块,也能像上面一样利用 rlcompleter 来做些很厉害的效果。嗯,今天的装逼到此为止。
向下滚动可载入更多评论,或者点这里禁止自动加载。