|
交互式命令行可以通过启动文件来配置。当它启动时候查找环境变量PYTHONSTARTUP,并且执行该变量中指定文件里的程序代码。有些Linux发行版本提供了一个默认的启动脚本,它通常放在用户主目录下,文件名是.pythonstartup。按Tab键时自动不全内容和命令历史。它们都是对命令行的有效增强,这些工具是基于readline模块实现的(需要readline程序库)。如果没有这个启动脚本,也可以自己创建一个。
下面是一个最简单的启动脚本文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # python startup file
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的官方网站上下载一个
https://pypi.python.org/pypi/pbp.scripts/0.2.5,
这个压缩包中包含pythonstartup的文件,将它重命名.pythonstartup放入到用户目录,添加到环境即可。
将这句添加到/etc/profile中
export PYTHONSTARTUP=~/.pythonstartup
然后source /etc/profile,就可以生效了。
1
2
3
4
5
6
7
8
9
| [iyunv@localhost ~]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5
>>> md5.
md5.__class__( md5.__doc__ md5.__getattribute__( md5.__name__ md5.__reduce__( md5.__setattr__( md5.__subclasshook__( md5.md5(
md5.__delattr__( md5.__file__ md5.__hash__( md5.__new__( md5.__reduce_ex__( md5.__sizeof__( md5.blocksize md5.new(
md5.__dict__ md5.__format__( md5.__init__( md5.__package__ md5.__repr__( md5.__str__( md5.digest_size md5.warnings
|
|
|