#python tab命令补全脚本
1. 建立python学习目录,将学习目录加入PATH环境变量中。
mkdir /opt/workspace/Python *#自定义python学习目录*
vim /etc/profile
PATH=${PATH}:/opt/workspace/Python *#加入环境变量*
source /etc/profile
2. 使用别名快捷进入工作目录。
alias py='cd /opt/workspace/Python'
vim ~/.bashrc
#add some aliases by maunal
alias py='cd /opt/workspace/Python'
source ~/.bashrc
py
pwd *#查看是否在工作目录*
3. 创建自动补全tab Module脚本。
vim /opt/workspace/Python/tab.py
#!/usr/bin/env python
# python startup file
"""Python Auto-tab module""" *#这时候在执行python指令进入交互式Shell后,再执行import tab带入tab模块即可以实现自动补全功能。*
import sys
import readline
import rlcompleter
import atexit
improt os
# tab completion
readline.parse_add_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
4. import tab指令需要在tab.py文件的当前目录下执行,而且每次登入到PythonShell时都需要执行一次,非常的不方便,可以通过修改~/.bashrc文件来实现自动带入tab Module。
vim ~/.bashrc
#Add the content as below.
export PYTHONSTARTUP=/opt/workspace/Python/tab.py
source /etc/profile
source ~/.bashrc
python tab
python
>>>import tab
第一次写博客,大家多多支持哦 么么-z-