• <output id="aynwq"><form id="aynwq"><code id="aynwq"></code></form></output>

    <mark id="aynwq"><option id="aynwq"></option></mark>
  • <mark id="aynwq"><option id="aynwq"></option></mark><label id="aynwq"><dl id="aynwq"></dl></label>
  • 學習啦 > 學習電腦 > 電腦安全 > 系統安全 > Linux為Python添加TAB自動補全和命令歷史功能

    Linux為Python添加TAB自動補全和命令歷史功能

    時間: 林澤1002 分享

    Linux為Python添加TAB自動補全和命令歷史功能

      為Python添加交互模式下TAB自動補全以及命令歷史功能。如何操作呢?下面是學習啦小編跟大家分享的是Linux為Python添加TAB自動補全和命令歷史功能,歡迎大家來閱讀學習。

      Linux為Python添加TAB自動補全和命令歷史功能

      方法/步驟

      Linux Python Tab 自動補全方法:

      新建Python環境變量配置文件:

      vim ~/.pystartup

      # Add auto-completion and a stored history file of commands to your Python

      # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is

      # bound to the Esc key by default (you can change it - see readline docs).

      #

      # Store the file in ~/.pystartup, and set an environment variable to point

      # to it: "export PYTHONSTARTUP=~/.pystartup" in bash.

      import atexit

      import os

      import readline

      import rlcompleter

      readline.parse_and_bind('tab: complete')

      historyPath = os.path.expanduser("~/.pyhistory")

      def save_history(historyPath=historyPath):

      import readline

      readline.write_history_file(historyPath)

      if os.path.exists(historyPath):

      readline.read_history_file(historyPath)

      atexit.register(save_history)

      del os, atexit, readline, rlcompleter, save_history, historyPath

      設置Python環境變量:

      即時生效,重啟失效:export PYTHONSTARTUP=~/.pystartup

      永久生效:echo "export PYTHONSTARTUP=~/.pystartup" >> /etc/profile

      驗證:

      注:默認補全是ESC。

      readline.parse_and_bind('tab: complete') 這條命令用來設定為tab補全。

      Windows Python Tab 自動補全方法:

      a. 安裝python

      b. pip install pyreadline

      c. 在Python安裝路徑的Lib文件夾下新建一個tab.py

      例如:C:\Program Files (x86)\Python2\Lib

      用編輯器編輯:

      # Add auto-completion and a stored history file of commands to your Python

      # interactive interpreter.

      import atexit

      import os

      import readline

      import rlcompleter

      import sys

      # Tab completion

      readline.parse_and_bind('tab: complete')

      # history file

      histfile = os.path.join("D:\Tmp\history\", ".pythonhistory")

      try:

      readline.read_history_file(histfile)

      except IOError:

      pass

      atexit.register(readline.write_history_file, histfile)

      del os, histfile, readline, rlcompleter

      注:

      histfile = os.path.join("D:\Tmp\history\", ".pythonhistory") 這個路徑可以自定義設置。

      d. 輸入python就自動加載tab補全

      和linux類似,如果想輸入python就自動加載tab補全,在系統屬性中的環境變量里增加PYTHONSTARTUP變量,值為絕對路徑的 tab.py,例如:

      變量名:PYTHONSTARTUP

      變量值:C:\Program Files (x86)\Python2\Lib\tab.py

      注:不做這步的話,每次輸入python進入交互界面后,需要手動import tab


    Linux為Python添加TAB自動補全和命令歷史功能相關文章:

    1.如何用Python寫Linux命令

    2.很實用的Linux 系統運維常用命令

    3.Linux下用Python獲取命令行輸出的幾個方案

    4.python版本低怎么升級

    5.Python如何獲取Linux管道輸出

    6.局域網python封裝linux監控模塊

    3085531 主站蜘蛛池模板: 无码夫の前で人妻を侵犯| 午夜视频在线观看区二区| 国产精品成人免费视频网站| 天天摸天天干天天操| 强行交换配乱婬bd| 思思久久99热只有频精品66| 欧美卡一卡2卡三卡4卡在线| 色中文字幕在线| youjizz亚洲| a级毛片在线免费| A级国产乱理伦片| 99久在线观看| 三大高傲校花被调教成好文 | 日韩精品一区二区三区在线观看| 欧美亚洲天堂网| 欧美精品www| 永久在线免费观看| 精品久久亚洲中文无码| 一级白嫩美女毛片免费| 久久精品视频免费看| 亚洲国产激情一区二区三区| 亚洲综合色丁香麻豆| 伊甸园在线观看国产| 国产偷v国产偷v亚洲高清| 国产精品欧美亚洲| 夜夜嗨AV一区二区三区| 国产精彩对白综合视频| 在线观看黄的网站| 国产精品冒白浆免费视频| 国产曰批免费视频播放免费s| 国产天堂亚洲精品| 国产男女猛烈无遮挡免费视频| 国产性生大片免费观看性| 国产h视频在线| 亚洲色欲久久久综合网东京热| 又湿又紧又大又爽a视频| 人妻体内射精一区二区| 亚洲国产成人精品无码一区二区| 亚洲精品亚洲人成在线观看| 亚洲精品欧美精品国产精品| 亚洲精品国产啊女成拍色拍|