unbtun python tab补全

it2022-05-21  83

在使用python的时候有时候总是忘记很多代码,这个是作为程序袁最头疼的事情,本人也是刚刚接触python,这几天也是用到这块,所以记录下来,已被需要时能够找到。 我的系统是: 1 w@w:~$ uname -a 2 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安装路径,如果不知道的话可以根据下面的方法查看以下: 1 w@w:~$ python 2 Python 2.7.10 (default, Oct 14 2015, 16:09:02)  3 [GCC 5.2.1 20151010] on linux2 4 Type  " help "" copyright "" credits "  or  " license "  for more information. 5 >>>  import sys 6 >>> sys.path 7 [ ''' /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的安装路径,把下面的代码传进去  1  # !/usr/bin/python  2  #  python startup file  3  import sys  4  import readline  5  import rlcompleter  6  import atexit  7  import os  8  #  tab completion  9  readline.parse_and_bind( ' tab: complete ') 10  #  history file 11  histfile = os.path.join(os.environ[ ' HOME '],  ' .pythonhistory ') 12  try: 13     readline.read_history_file(histfile) 14  except IOError: 15      pass 16 atexit.register(readline.write_history_file, histfile) 17  del os, histfile, readline, rlcompleter 所传路径以及文件名称可以随意,但是在调用的时候要一致。但是文件必须传到python路径下:  1 w@w:/usr/lib/python2.7/dist-packages$ vi tab.py   2  # !/usr/bin/python  3  #  python startup file  4  import sys  5  import readline  6  import rlcompleter  7  import atexit  8  import os  9  #  tab completion 10  readline.parse_and_bind( ' tab: complete ') 11  #  history file 12  histfile = os.path.join(os.environ[ ' HOME '],  ' .pythonhistory ') 13  try: 14     readline.read_history_file(histfile) 15  except IOError: 16      pass 17 atexit.register(readline.write_history_file, histfile) 18  del os, histfile, readline, rlcompleter 我把文件传到/usr/lib/python2.7/dist-packages目录下,并且用tab.py命名。 1 w@w:~$ vi .bashrc 2  # for python     3  export PYTHONSTARTUP=/usr/lib/python2.7/dist-packages/tab.py 4  # 上面的路径和文件名必须和上面的保持一致。 5  w@w:~$ source .bashrc  # 启用上面的环境

 

转载于:https://www.cnblogs.com/wulaoer/p/5032301.html


最新回复(0)