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

[root@mm_local ~]# echo "export PYTHONSTARTUP='/root/.pythonstartup'" >> /root/.bashrc 
[root@mm_local ~]# source /root/.bashrc
[root@mm_local ~]# cat /root/.pythonstartup 
import os
import readline
import rlcompleter
import atexit


#tab completion
readline.parse_and_bind("tab: complete")


#history file
history_file = os.path.join(os.environ["HOME"],".pythonhistory")
try:
    readline.read_history_file(history_file)
except IOError:
    pass
atexit.register(readline.write_history_file,history_file)


del os,history_file,readline,rlcompleter
[root@mm_local ~]# python
Python 2.7.3 (default, Jun  5 2013, 22:40:26) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path<tab> #按tab键就可以自动补全了

[root@mm_local ~]# python
>>>
>>> sys.path #按上下方向键即可找到历史命令

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值