• python实现tab键自动补全


    一、查询python安装路径,一般默认是/usr/lib64/

    [root@host2 ~]# python
    Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] 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/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages']

    二、切换到python的安装目录下,编辑tab键补全模块

    [root@host2 ~]# cd /usr/lib64/python2.6/
    [root@host2 python2.6]# vim tab.py
    #!/usr/bin/env python
    # python startup 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

    三、修改~/.bashrc

    [root@host2 python2.6]# echo "export PYTHONSTARTUP=/usr/lib64/python2.6/tab.py" >> ~/.bashrc
    [root@host2 python2.6]# source ~/.bashrc

    四、进入python测试,可正常使用tab补全功能了

  • 相关阅读:
    Google
    LeetCode 664. 奇怪的打印机
    LeetCode 79. 单词搜索
    LeetCode 224. 基本计算器
    Windows 端口映射
    LeetCode 354. 俄罗斯套娃信封问题
    LeetCode 300. 最长递增子序列
    LeetCode 338. 比特位计数
    LeetCode 395. 至少有K个重复的最长子串
    LeetCode 424. 替换后的最长重复字符
  • 原文地址:https://www.cnblogs.com/01-single/p/7839802.html
Copyright © 2020-2023  润新知