python - readline 模組

來源:互聯網
上載者:User

標籤:python   read   定位   gid   pre   mat   令行   鉤子函數   tps   

轉載:https://www.cnblogs.com/fireflow/p/4841413.html

 

  readline模組定義了一系列函數用來讀寫Python解譯器中曆史命令,並提供自動補全命令功能。這個模組可以通過relcompleter模組直接調用,模組中的設定會影響解譯器中的互動提示,以及內建函數raw_input()和input()提供的提示。

 

# readline模組定義了以下方法:        readline.parse_and_bind(string): # 解析並執行命令列初始設定檔案。        readline.get_line_buffer(): # 返回當前命令列緩衝的內容。        readline.insert_text(string): # 插入到當前行。        readline.read_init_file([filename]): # 解析一個命令列初始設定檔案。        readline.read_history_file([filename]): # 讀取曆史命令檔案,預設為~/.history        readline.write_history_file([filename]): # 儲存曆史命令檔案,預設為~/.history        readline.get_history_length(): # 擷取預設的曆史命令條數。負數意味著不限制條數大小。        readline.set_history_length(length): # 設定要儲存到曆史命令檔案中的命令條數,write_history_file()使用這個數字對曆史命令檔案進行修改。        readline.get_current_history_length(): # 返回當前曆史檔案中曆史命令的條數。        readline.get_history_item(index): # 擷取index索引指定的曆史命令。        readline.remove_history_item(pos): # 刪除指定位置的曆史命令。        readline.replace_history_item(pos, line) : # 使用給定命令替換指定位置的命令。        readline.redisplay() : # 根據命令列緩衝即時更新當前螢幕的顯示。        readline.set_startup_hook([function]) : # 設定或刪除鉤子函數,如果指定了函數,就將其設為鉤子函數,\
                               如果沒有指定或者設定為None,所有已經安裝的鉤子函數將被移除,鉤子函數在命令列輸出提示前執行。 readline.set_pre_input_hook([function]): # 跟set_startup_hook()方法類似,但是鉤子函數是在提示輸入完之後,命令列開始讀取字串之前執行。 readline.set_completer([function]): # 如果提供了函數,則用作自動完成命令函數,如果忽略或者設定為None,則移除之前設定的函數。 \
                            命令自動完成函數形式如function(text,state),text為命令列中輸入的字串,state為選擇的的補全命令索引。 readline.get_completer(): # 返回自動完成命令函數。 readline.get_completion_type() : # 返回自動完成的類型。 readline.get_begidx() : # 擷取命令列tab自動補全範圍的第一個值的索引。 readline.get_endidx() : # 擷取命令列tab自動補全範圍的最後一個值的索引。 readline.set_completer_delims(string) : # 設定自動補全命令之間的分隔字元。 readline.get_completer_delims() : # 擷取分隔字元。 readline.set_completion_display_matches_hook([function]) : # 設定或者移除自動完成顯示函數。 readline.add_history(line) : # 添加最後一條輸入的命令到曆史檔案中。

 

python - readline 模組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.