python tab补全_unbtun python tab补全

在使用python的时候有时候总是忘记很多代码,这个是作为程序袁最头疼的事情,本人也是刚刚接触python,这几天也是用到这块,所以记录下来,已被需要时能够找到。

我的系统是:w@w:~$ 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安装路径,如果不知道的话可以根据下面的方法查看以下:w@w:~$ 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路径下:w@w:/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命名。w@w:~$ vi .bashrc

#for python

export PYTHONSTARTUP=/usr/lib/python2.7/dist-packages/tab.py

#上面的路径和文件名必须和上面的保持一致。

w@w:~$ source .bashrc #启用上面的环境

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值