zoukankan      html  css  js  c++  java
  • python tab complete

    一、查询python安装路径,一般默认是/usr/bin/

    moonx@moonx:/usr/download/test/mypython$ python

    Python 2.7.12 (default, Oct 8 2019, 14:14:10)
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path
    ['', '/opt/stack/keystone', '/opt/stack/glance', '/opt/stack/neutron', '/opt/stack/nova', '/opt/stack/horizon', '/opt/ros/kinetic/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/moonx/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']
    >>>

    二、切换到python的安装目录下,编辑tab键补全模块

      moonx@moonx:/usr/download/test/mypython$ cd /usr/local/lib/python2.7/
      moonx@moonx:/usr/local/lib/python2.7$ pwd
      /usr/local/lib/python2.7
      moonx@moonx:/usr/local/lib/python2.7$ vi 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

    三、修改~/.bashrc

    moonx@moonx:/usr/local/lib/python2.7$ echo "export PYTHONSTARTUP=/usr/local/lib/python2.7/tab.py" >> ~/.bashrc
    moonx@moonx:/usr/local/lib/python2.7$ source ~/.bashrc

    四、进入python测试,可正常使用tab补全功能了

    moonx@moonx:/usr/download/test/mypython$ python
    Python 2.7.12 (default, Oct 8 2019, 14:14:10)
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import simple_package
    >>> simple_package

  • 相关阅读:
    父子进程 signal 出现 Interrupted system call 问题
    一个测试文章
    《淘宝客户端 for Android》项目实战 html webkit android css3
    Django 中的 ForeignKey ContentType GenericForeignKey 对应的数据库结构
    coreseek 出现段错误和Unigram dictionary load Error 新情况(Gentoo)
    一个 PAM dbus 例子
    漫画统计学 T分数
    解决 paramiko 安装问题 Unable to find vcvarsall.bat
    20141202
    js
  • 原文地址:https://www.cnblogs.com/cjyp/p/11764075.html
Copyright © 2011-2022 走看看