• 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(
    ......
    

      

  • 相关阅读:
    脏数据或者场景考虑不全面引发的生产问题
    框架那些事
    RMI远程方法调用和rpc远程过程调用
    如何提高开发效率
    什么是RPC
    TCP/IP协议和HTTP协议
    apache常见错误:VC运行库(找不到 VCRUNTIME140.dll)
    Apache报错:无法使用可靠的服务器域名
    Apache2.4 下载和安装
    Navicat Premium 15.0.17 破解激活(DFoX 注册机)
  • 原文地址:https://www.cnblogs.com/abclife/p/6291772.html
Copyright © 2020-2023  润新知