• Python2.7设置在shell脚本中自动补全功能的方法


    1.新建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
    

    2.把上面的代码,保存成tab.py文件,然后保存到下面的指定路径之一

    >>> import sys
    >>> sys.path
    ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
    

     为了省事点,我直接把tab.py文件放到/usr/lib/python2.7这个目录下面好了

    3.使用方法

    需要补全函数时按下tab键即可

  • 相关阅读:
    (转)介绍一些.net开源项目
    (转).Net有哪些大型项目、大型网站的案例?
    Linux下的awk使用
    linux下的sed使用
    linux下的find、grep、cut使用
    CentOS7下的Zabbix4.4安装配置
    NetBackup linux客户端安装
    bat小脚本
    批量复制指定目录下的文件,并统计执行时间
    iptables
  • 原文地址:https://www.cnblogs.com/hester/p/10422803.html
Copyright © 2020-2023  润新知