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

      

  • 相关阅读:
    struts2之JSP与Action的关系
    struts2之基本配置
    Android笔记之BroadCast判断网络状况
    Android笔记之监听左右滑动事件
    Android笔记之转到主线程运行
    springboot项目启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedde
    centos6 初次安装成功,未显示eth0网卡的信息
    layerui上传文件
    判断当前浏览器类型
    jquery重置下拉框
  • 原文地址:https://www.cnblogs.com/abclife/p/6291772.html
Copyright © 2020-2023  润新知