python上翻历史命令_Python实现Tab自动补全和历史命令管理的方法

Python的startup文件,即系统变量 PYTHONSTARTUP 相匹配的文档

1. 为readline加上tab键全自动补齐的作用

2. 像Shell一样管理方法历史时间指令

编码以下:

编码以下:import rlcompleter

import readline

import atexit

import os

#

if ‘libedit’ in readline.__doc__:

readline.parse_and_bind(‘bind ^I rl_complete’)

else:

readline.parse_and_bind(‘tab: complete’)

histfile = os.path.join(os.environ[‘HOME’], ‘.pyhist’)

try:

readline.read_history_file(histfile)

except IOError:

pass

atexit.register(readline.write_history_file, histfile)

del readline, rlcompleter, histfile, os

期待文中上述对大伙儿的Python编程设计有一定的协助。

一。这一方式能够改动shellcmd的全自动补齐

1.获得python文件目录【我应用的是64位ubuntu系统软件】[~$]pythonPython 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information. import sys sys.path['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/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/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0','/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

从上边看得出python在我电脑的途径是 /usr/lib/python2.7

2.转换至该文件目录写个startup.py的脚本制作,脚本制作文件目录便是解决python中tab恶性事件,脚本制作內容以下#!/usr/bin/python # python startup fileimport 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

3.转换至自身主目录

编码以下:

[/usr/lib/python2.7$]cd

[~$]vi .bashrc

4. 提升系统变量

编码以下:

#for python

export PYTHONSTARTUP=/usr/lib/python2.7/startup.py

5.配备系统变量起效

编码以下:

[~$]source .bashrc

PYTHONSTARTUP是什么东西呢?

编码以下:

If this is the name of a readable file, the Python commands in that file are executed before the first prompt

is displayed in interactive mode. The file is executed in the same name space where interactive commands are

executed so that objects defined or imported in it can be used without qualification in the interactive session.

You can also change the prompts sys.ps1 and sys.ps2 in this file.

二。这一方式能在VIM中全自动补齐

1. 下载插件:

下载链接:https://www.jb51.net/softs/305586.html

2.复制致相对的文件目录

编码以下:

unzip pydiction-1.2.1.zip

cp python_pydiction.vim /usr/share/vim/vim73/ftplugin

mkdir /usr/share/vim/vim73/pydiction

cp complete-dict /usr/share/vim/vim73/pydiction/

cp pydiction.py /usr/share/vim/vim73/pydiction/

3.改动vim配置文档

编码以下:

let g:pydiction_location = ‘/usr/share/vim/vim73/pydiction/complete-dict’

let g:pydiction_menu_height = 20文章内容来源于:www.seo-7.comwww.sEo-6.comhttp://www.seo-6.com/seoyh/seojichurm/118219.html

(编辑:部分内容来互联网)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值