unbtun python tab补全

作者: 网络编程  发布:2019-09-03

unbtun python tab补全

在应用python的时候有的时候总是忘记广大代码,这一个是作为程序袁最胸口痛的政工,本身也是刚刚接触python,近日也是用到那块,所以记录下来,已被亟需时亦可找到。

自己的系统是:

 

[email protected]:~$ uname -a
Linux w 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

 

先看看本人的python安装路线,假如不明白的话能够依照上面包车型地铁主意查看以下:

 

[email protected]:~$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/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', '/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/ubuntu-sso-client']

 

既然如此找到了python的设置路线,把下边包车型大巴代码传进去

 

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

 

 

所传路线以及文件名称能够自由,可是在调用的时候要一律。不过文件必需传到python路线下:

 

[email protected]:/usr/lib/python2.7/dist-packages$ vi tab.py 
#!/usr/bin/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

 

 

本身把公文字传递到/usr/lib/python2.7/dist-packages目录下,并且用tab.py命名。

 

[email protected]:~$ vi .bashrc
#for python    
export PYTHONSTARTUP=/usr/lib/python2.7/dist-packages/tab.py
#上面的路径和文件名必须和上面的保持一致。

 

 

[email protected]:~$ source .bashrc #启用上边的情形

python tab补全 在行使python的时候不时总是忘记广大代码,那一个是用作程序袁最发烧的政工,本身也是刚刚接触python,最近也是用到...

python 添加tab补全,pythontab补全

在平日查看Python方法用到tab补全照旧很便利的。

    1. mac 平台 配置如下:
    •   mac是类Unix平台,须求在丰裕一条配置内容到bash_profile 中(默许是从没有过那个文件,能够新建二个身处宿主目录上面)

      •   先新建三个tab.py的文件内容如下:
      • import rlcompleter,sys,readline

        if sys.platform == 'darwin' and sys.version_info[0] == 2:
            readline.parse_and_bind("bind ^I rl_complete")
        else:
            readline.parse_and_bind("tab: complete")
        
  •  查看当前系统的Python解释器路线

    Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path
    ['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/beautifulsoup4-4.4.1-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests-2.9.0-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/testkit_lite-3.1.14-py2.7.egg', '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
    

     

  • 将刚刚新建好的tab.py 文件复制到解释器路线上边,一般放置在‘/Library/Python/2.7/site-packages/’目录上边

    •   sudo cp tab.py /Library/Python/2.7/site/packages/
  • 将配备文件的音信写入到 ~/.bash_profile 中,假诺文件存在则增多在文件内容后,假如不设有则新建该公文
    • vi ~/.bash_profile    保存退出然后 source ~/.bash_profile   (让该配置文件生效)
    • export PYTHONSTARTUP=/Library/Python/2.7/site-packages/tab.py

        然后步入Python import tab 用tab则足以列出子方法如下

Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab,sys
>>> sys.
Display all 101 possibilities? (y or n) 
sys.__class__(             sys.__hash__(              sys.__sizeof__(            sys.callstats(             sys.getfilesystemencoding( sys.prefix                
sys.__class__(             sys.__init__(              sys.__stderr__             sys.copyright              sys.getprofile(            sys.ps1                   
sys.__class__(             sys.__init__(              sys.__stdin__              sys.displayhook(           sys.getrecursionlimit(     sys.ps2                   
sys.__delattr__(           sys.__name__               sys.__stdout__             sys.dont_write_bytecode    sys.getrefcount(           sys.py3kwarning           
sys.__delattr__(           sys.__new__(               sys.__str__(               sys.exc_clear(             sys.getsizeof(             sys.setcheckinterval(     
sys.__dict__               sys.__new__(               sys.__str__(               sys.exc_info(              sys.gettrace(              sys.setdlopenflags(       
sys.__displayhook__(       sys.__package__            sys.__subclasshook__(      sys.exc_type               sys.hexversion             sys.setprofile(           
sys.__doc__                sys.__plen                 sys.__subclasshook__(      sys.excepthook(            sys.long_info              sys.setrecursionlimit(    
sys.__doc__                sys.__reduce__(            sys._clear_type_cache(     sys.exec_prefix            sys.maxint                 sys.settrace(             
sys.__doc__                sys.__reduce__(            sys._current_frames(       sys.executable             sys.maxsize                sys.stderr                
sys.__egginsert            sys.__reduce_ex__(         sys._getframe(             sys.exit(                  sys.maxunicode             sys.stdin                 
sys.__excepthook__(        sys.__reduce_ex__(         sys._mercurial             sys.flags                  sys.meta_path              sys.stdout                
sys.__format__(            sys.__repr__(              sys.api_version            sys.float_info             sys.modules                sys.subversion            
sys.__format__(            sys.__repr__(              sys.argv                   sys.float_repr_style       sys.path                   sys.version               
sys.__getattribute__(      sys.__setattr__(           sys.builtin_module_names   sys.getcheckinterval(      sys.path_hooks             sys.version_info          
sys.__getattribute__(      sys.__setattr__(           sys.byteorder              sys.getdefaultencoding(    sys.path_importer_cache    sys.warnoptions           
sys.__hash__(              sys.__sizeof__(            sys.call_tracing(          sys.getdlopenflags(        sys.platform              
>>> sys.

 

2.Ubuntu类其他安插文件和Mac有一点不等同,一样写入一个tab.py文件到Python解释器路线下,其余的操作都毫不,增多的代码如下:

sudo vi /usr/lib/python2.7/dist-packages/tab.py

import sys,readline,rlcompleter,atexit,os

readline.parse_and_bind('tab: complete')
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

 

            

加多tab补全,pythontab补全 在平日查阅Python方法用到tab补全依然很有益的。 1. mac 平台 配置如下: mac是类Unix平台,必要在加上一条配置...

本文由王中王开奖结果发布于网络编程,转载请注明出处:unbtun python tab补全

关键词: