首先需要知道Python的读取路径>>> import sys
>>> sys.path
["", "/usr/lib64/python26.zip", "/usr/lib64/python2.6", "/usr/lib64/python2.6/plat-linux2", "/usr/lib64/python2.6/lib-tk", "/usr/lib64/python2.6/lib-old", "/usr/lib64/python2.6/lib-dynload", "/usr/lib64/python2.6/site-packages", "/usr/lib/python2.6/site-packages"]可以看到python可以去这些地方读取,我们把脚本放在/usr/lib64/python2.6 即可[root@python python2.6]# cat startup.py
#!/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这样做一个问题就是,你每次启动python后,都需要手动导入一下,比如>>> import startup可以在系统环境变量中,加入读取路径,这样就免去了每次导入的麻烦[root@python python2.6]# cat ~/.bashrcexport PYTHONSTARTUP=/usr/lib64/python2.6/startup.py即可。无需操作系统直接运行 Python 代码 http://www.linuxidc.com/Linux/2015-05/117357.htmCentOS上源码安装Python3.4 http://www.linuxidc.com/Linux/2015-01/111870.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htmPython 的详细介绍:请点这里
Python 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-05/117888.htm