python import readline_readline在python哪个库
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) :添加最后一条输入的命令到历史文件中。
示例:
下面的例子使用readline模块从.pyhist中读取历史命令,并自动保存历史命令到这个文件中。import os
histfile = os.path.join(os.environ["HOME"],".pyhist")
try:
readline.read_history_file(histfile)
exceptIOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile
下面的例子通过继承code.InteractiveConsole来支持历史命令的读写。import code
import readline
import atexit
import os
classHistoryConsole(code.InteractiveConsole):
def __init__(self, locals=None, filename="",
histfile=os.path.expanduser("~/.console-history")):
code.InteractiveConsole.__init__(self, locals, filename)
self.init_history(histfile)
def init_history(self, histfile):
readline.parse_and_bind("tab: complete")
if hasattr(readline,"read_history_file"):
try:
readline.read_history_file(histfile)
exceptIOError:
pass
atexit.register(self.save_history, histfile)
def save_history(self, histfile):
readline.write_history_file(histfile)
python学习网,免费的在线学习python平台,欢迎关注!
python import readline_readline在python哪个库相关推荐
- python import找不到so库的可能原因
gen 在import一个so库里的类或函数时,有时发现so文件分明就在那路径下,可是总是报错ModuleNotFoundError: No module named ***,这种错误的可能原因有: ...
- python import turtle as t_Python turtle库的学习笔记
(2)from turtle import * 对turtle库中函数调用采用( )形式,不再使用turtle.作为前导: (3) import turtle as t 保留字as将turtle库给 ...
- python import random函数-Python代码中的“import random”是什么意思?
匿名用户 1级 2017-12-02 回答 导入python提供的random这个库. Python代码例子 1.输入三个变量,然后按小到大输出 [python] view plain copy x ...
- python import注意事项
# 基本概念 ## 模块&包简介 模块:所谓模块就是一个.py文件,用来存放变量,方法的文件,便于在其他python文件中导入(通过import或from). 包(package): 包是更大 ...
- python调用so库 undefind symbol_内嵌Python import时undefined symbol错误及解决 | 学步园
内嵌Python import时undefined symbol错误及解决 以下代码 #include#include#includeintmain(intargc,char*argv[]) ...{ ...
- VSCode:python import下载的第三方库,报错问题解决
问题 无论怎么设置,以及在import requests或者 from requests_toolbelt import sessions总是出现 No module named 的错误. 解决办法 ...
- Python import 的用法
我们刚开始接触python 看到了很多python 的很多库 比如添加log 的库logging import logginglogging.error("error:直接输入log日志&q ...
- 在Ubuntu 16.04.5 LTS上利用python 2.7版本的pillow库拼接近千张图片实录
缘由 这两年网上出现了使用python中的PIL或是pillow库拼接图片和朋友圈图像的例子,让我非常感兴趣,比较典型的是这几个例子: <朋友圈的朋友们,你们终于可以互相看到了> < ...
- python requests 重定向_认识Python最最最常用语重要的库Requests
Requests库是Python爬虫中最最最最最最重要与常见的库,一定要熟练掌握它.下面我们来认识这个库 Requests requests是Python最为常用的http请求库,也是极其简单的.使用 ...
最新文章
- 递归思想解决输出目录下的全部文件
- saccharomyces_cerevisiae 酿酒酵母
- iphone字体_iOS 13终于能换花式字体了?!发在朋友圈里真的超好看!
- Attribute ‘sklearn.linear_model._logistic.LogisticRegression.multi_class‘ must be explicitly set to
- mysql 聚簇索引和非聚簇索引_MySQL 聚簇索引 二级索引 辅助索引(上两期中奖名单)...
- linux查看网卡硬件 lsw,无人值守网络安装Linux系统
- PAT1057. 数零壹
- bankbone 模型简单介绍
- java web个人博客开发(一需求获取和需求分析文档)
- UDS学习笔记(六)——程序刷写
- Qt编写Modbus从机程序
- 校招软件测试面经篇二(国企、银行、运营商等)
- 用金山打字通练习Java常用单词
- 罗永浩如果倒过来过,也很励志
- 35岁后你的职场危机,你该何去何从
- android修改文件名,android 修改文件名称
- 详细讲解BM字符串搜索算法
- php获取蓝凑云文件列表,PHP获取蓝奏云直链下载地址
- HTML编辑器选择什么,HTML编辑器有哪些?3款常用的编辑器推荐
- sql语法:详解DDL