zoukankan      html  css  js  c++  java
  • python命令行添加Tab键自动补全

    1、编写一个tab的自动补全脚本,名为tab.py

    #!/usr/bin/python 
    # python tab complete 
    
    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中查看python的模块路径信息

    >>> import sys
    >>> sys.path
    ['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/gst-0.10', '/usr/lib/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages/webkit-1.0']
    >>> 

    python的模块放在了/usr/lib/python26下面,将脚本拷贝到该目录下,在使用时导入即可。

    3、导入tab

    >>> import tab
    >>> os.
    Display all 244 possibilities? (y or n)

     4、但python读取模块的路径顺序优先是从当前目录开始,所以若是当前目录也存在tab.py,但内容不同的python脚本,则可能会报错,所以在环境变量中也指定tab.py脚本

    #for python
    export PYTHONSTARTUP=/usr/lib/python2.6/tab.py
  • 相关阅读:
    015.Python基础--模块
    014.Python基础--格式化输入输出
    013.Python基础--异常/错误处理
    012.Python基础--装饰器深入
    011.Python基础--装饰器
    010.Python基础--生成器
    汇编的角度分析指针-03(字符串深入理解)
    汇编的角度分析C语言的指针-02
    汇编的角度分析C语言的switch语句
    分析C语言的字节对齐
  • 原文地址:https://www.cnblogs.com/xiaotengyi/p/3996528.html
Copyright © 2011-2022 走看看