python Tab自动补全命令设置

Posted on 2015-12-30 11:32  Vincent90  阅读(416)  评论(0编辑  收藏  举报

Mac/Windows下需要安装模块儿

pip install pyreadline
pip install rlcompleter
pip install readline

  注意,需要先安装pyreadline之后才能顺利安装readline

 

Mac 下代码如下

>>> import rlcompleter
>>> import readline
>>> import os
>>> import sys
>>> 
>>> if 'libedit' in readline.__doc__:
...     readline.parse_and_bind("bind ^I rl_complete")
... else:
...     readline.parse_and_bind("tab: complete")
... 
>>> sys.__
sys.__class__(        sys.__egginsert       sys.__init__(         sys.__reduce__(       sys.__stderr__       
sys.__delattr__(      sys.__excepthook__(   sys.__name__          sys.__reduce_ex__(    sys.__stdin__        
sys.__dict__          sys.__format__(       sys.__new__(          sys.__repr__(         sys.__stdout__       
sys.__displayhook__(  sys.__getattribute__( sys.__package__       sys.__setattr__(      sys.__str__(         
sys.__doc__           sys.__hash__(         sys.__plen            sys.__sizeof__(       sys.__subclasshook__(
>>> sys.__

 

Windows环境下

>>> import rlcompleter
>>> import readline
>>> readline.parse_and_bind("tab: complete")
>>> import sys
>>> sys.__
sys.__class__(        sys.__hash__(         sys.__setattr__(
sys.__delattr__(      sys.__init__(         sys.__sizeof__(
sys.__dict__          sys.__name__          sys.__stderr__
sys.__displayhook__(  sys.__new__(          sys.__stdin__
sys.__doc__           sys.__package__       sys.__stdout__
sys.__excepthook__(   sys.__reduce__(       sys.__str__(
sys.__format__(       sys.__reduce_ex__(    sys.__subclasshook__(
sys.__getattribute__( sys.__repr__(
>>> sys.__

 

另外,可以配合raw_input() 函数使用

# -*- coding: utf8 -*-
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
raw_input("AA->:")

 

Copyright © 2024 Vincent90
Powered by .NET 9.0 on Kubernetes