標籤: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 模組