python的使用环境总结

来源:互联网 发布:js让一个div显示 编辑:程序博客网 时间:2024/06/08 03:58

python在linux上运行,使用的是vim,每次都是敲四个空格进行缩进,真尼玛的蛋疼,书本果然是个好东西,从而根据书本python高级编程中的设置配置而来:

1、进行自动补全的脚本

[root@python ~]# cat .pythonstartup #python startup fileimport readlineimport rlcompleterimport atexitimport os#tab completionreadline.parse_and_bind('tab:complete')#history filehistfile = os.path.join(os.environ['HOME'],'.pythonhistory')try:    readline.read_history_file(histfile)except IOError:    passatexit.register(readline.write_history_file,histfile)del os,histfile,readline,rlcompleter
主要是用来进行命令自动补全,和linux中的是一样一样的

写好这个之后,必须配置环境变量,在bash_profile中新增一项,如果没有这个文件在RHEL系列中,那么就是别的家目录文件中:

[root@python ~]# cat .bash_profile |grep PYTHONSexport PYTHONSTARTUP='.pythonstartup'
写好上面的两部之后,记得重新登录,或者直接读取环境变量,从而可以使用上面的设置:
[root@python ~]# source .bash_profile 


2、自动缩进

用来进行自动缩进,主要就是因为。。。需要打太多的空格来进行缩进,从而使用到的是vim的配置文件.vimrc

具体内容设置如下:

[root@python ~]# cat .vimrc set expandtabset textwidth=0set tabstop=4set softtabstop=4set shiftwidth=4set autoindentset smartindentset backspace=indent,eol,startset incsearchset ignorecaseset rulerset wildmenuset commentstring=\ #\ %sset foldlevel=0set clipboard+=unnamedsyntax enablesyntax on
基本意思就是缩进的时候,使用的tab是四个空格,进行自动和只能缩进,增强搜索,并且忽略大小写,语法高亮


有了这个,再也不需要打无数个空格而烦恼,也不用说几个空格就是规范了。



0 0