1. 定义环境变量PYTHONSTARTUP
    编辑自己的.bashrc文件 
    export PYTHONSTARTUP=~/.pythonstartup

    这样,Python命令行在启动时就会加载当前用户下的.pythonstartup文件。
    也可以直接在命令行中键入上述,来做第一次尝试:)
  2. 定制.pythonstartup文件
    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命令行后,就有自动补全和命令行历史了。

相关文章:

  • 2021-07-27
  • 2021-07-21
  • 2021-11-25
  • 2021-06-30
  • 2021-12-03
  • 2021-12-10
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-12-05
  • 2021-12-23
相关资源
相似解决方案