python中的tab补全功能添加

用Python时没有tab补全还是挺痛苦的,记录一下添加该功能的方法利人利己

1. 先准备一个tab.py的脚本

  shell> cat tab.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python
# python tab file
  
import  sys
import  readline
import  rlcompleter
import  atexit
import  os
# tab completion
readline.parse_and_bind( 'tab: complete' )
# history file
histfile  =  os.path.join(os.environ[ 'HOME' ],  '.pythonhistory' )
try :
     readline.read_history_file(histfile)
except  IOError:
     pass
atexit.register(readline.write_history_file, histfile)
  
del  os, histfile, readline, rlcompleter

2. 查看Python默认的模块存放地址

1
2
3
4
5
6
7
[root@localhost ~] # python
Python  2.6 . 6  (r266: 84292 , Nov  22  2013 12 : 16 : 22 )
[GCC  4.4 . 7  20120313  (Red Hat  4.4 . 7 - 4 )] on linux2
Type  "help" "copyright" "credits"  or  "license"  for  more information.
>>>  import  sys
>>> sys.path
[' ', ' / usr / lib64 / python26. zip ', ' / usr / lib64 / python2. 6 ', ' / usr / lib64 / python2. 6 / plat - linux2 ', ' / usr / lib64 / python2. 6 / lib - tk ', ' / usr / lib64 / python2. 6 / lib - old ', ' / usr / lib64 / python2. 6 / lib - dynload ', ' / usr / lib64 / python2. 6 / site - packages ', ' / usr / lib64 / python2. 6 / site - packages / gtk - 2.0 ', ' / usr / lib / python2. 6 / site - packages ', ' / usr / lib / python2. 6 / site - packages / setuptools - 0.6c11 - py2. 6.egg - info']

3. 拷贝该脚本到默认模块存放路径

1
cp  tab.py   /usr/lib64/python2 .6/

4. 现在可以用了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
>>>  import  tab
>>>  import  sys
>>> sys.
sys.__class__(              sys.__reduce_ex__(          sys.builtin_module_names    sys.exitfunc(               sys.last_type(              sys.py3kwarning
sys.__delattr__(            sys.__repr__(               sys.byteorder               sys.flags                   sys.last_value              sys.setcheckinterval(
sys.__dict__                sys.__setattr__(            sys.call_tracing(           sys.float_info              sys.maxint                  sys.setdlopenflags(
sys.__displayhook__(        sys.__sizeof__(             sys.callstats(              sys.getcheckinterval(       sys.maxsize                 sys.setprofile(
sys.__doc__                 sys.__stderr__              sys.copyright               sys.getdefaultencoding(     sys.maxunicode              sys.setrecursionlimit(
sys.__excepthook__(         sys.__stdin__               sys.displayhook(            sys.getdlopenflags(         sys.meta_path               sys.settrace(
sys.__format__(             sys.__stdout__              sys.dont_write_bytecode     sys.getfilesystemencoding(  sys.modules                 sys.stderr
sys.__getattribute__(       sys.__str__(                sys.exc_clear(              sys.getprofile(             sys.path                    sys.stdin
sys.__hash__(               sys.__subclasshook__(       sys.exc_info(               sys.getrecursionlimit(      sys.path_hooks              sys.stdout
sys.__init__(               sys._clear_type_cache(      sys.exc_type                sys.getrefcount(            sys.path_importer_cache     sys.subversion
sys.__name__                sys._current_frames(        sys.excepthook(             sys.getsizeof(              sys.platform                sys.version
sys.__new__(                sys._getframe(              sys.exec_prefix             sys.gettrace(               sys.prefix                  sys.version_info
sys.__package__             sys.api_version             sys.executable              sys.hexversion              sys.ps1                     sys.warnoptions
sys.__reduce__(             sys.argv                    sys.exit(                   sys.last_traceback          sys.ps2

转载于:https://www.cnblogs.com/yunfeiblogs/p/6774619.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值