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
(编辑:部分内容来互联网)