Python命令行自动补全和记录历史命令

来源:互联网 发布:云数据库怎么用 编辑:程序博客网 时间:2024/05/21 09:26
[root@mm_local ~]# echo "export PYTHONSTARTUP='/root/.pythonstartup'" >> /root/.bashrc [root@mm_local ~]# source /root/.bashrc[root@mm_local ~]# cat /root/.pythonstartup import osimport readlineimport rlcompleterimport atexit#tab completionreadline.parse_and_bind("tab: complete")#history filehistory_file = os.path.join(os.environ["HOME"],".pythonhistory")try:    readline.read_history_file(history_file)except IOError:    passatexit.register(readline.write_history_file,history_file)del os,history_file,readline,rlcompleter[root@mm_local ~]# pythonPython 2.7.3 (default, Jun  5 2013, 22:40:26) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path<tab> #按tab键就可以自动补全了[root@mm_local ~]# python>>>>>> sys.path #按上下方向键即可找到历史命令

原创粉丝点击