zoukankan      html  css  js  c++  java
  • python添加tab键自动补全功能

    默认python是没有tab键补全功能的:

    >>> import tab
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named tab
    >>> 
    

      

    创建tab.py文件

    # vi tab.py

    添加以下内容:

    #!/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
    

      

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

    # python
    Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
    [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path
    ['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']
    >>> 
    

      

    将tab.py文件拷贝到/usr/lib64/python2.7/

    # cp tab.py  /usr/lib64/python2.7/
    

      

    这样就可以使用tab补全了:

    >>> import tab
    >>> import sys
    >>> sys.
    sys.__class__(              sys.exitfunc(
    sys.__delattr__(            sys.flags
    sys.__dict__                sys.float_info
    sys.__displayhook__(        sys.float_repr_style
    sys.__doc__                 sys.getcheckinterval(
    sys.__excepthook__(         sys.getdefaultencoding(
    sys.__format__(             sys.getdlopenflags(
    sys.__getattribute__(       sys.getfilesystemencoding(
    ......
    

      

  • 相关阅读:
    How To Verify TLS Options in Windows
    How to auto-generate a C# class file from a JSON string [closed]
    javascript-questions
    What is the difference between application server and web server?
    Manjaro Rust环境搭建
    Trojan
    50 年的软件开发经验带给我的 63 个启示
    对《GGX》shader的分析-卡通渲染-罪恶装备
    科学迷信
    Tokio,Rust异步编程实践之路
  • 原文地址:https://www.cnblogs.com/abclife/p/6291772.html
Copyright © 2011-2022 走看看