cpython: 416db1a2fb81 (original) (raw)
Mercurial > cpython
changeset 99861:416db1a2fb81 3.5
#25991: fix readline example to limit history size. Patch by Daniel Dye. [#25991]
Ezio Melotti ezio.melotti@gmail.com | |
---|---|
date | Mon, 11 Jan 2016 23:30:56 +0200 |
parents | 1e9ec2d9f2d6 |
children | cb08e5271cc0 6bd4a4907f66 |
files | Doc/library/readline.rst |
diffstat | 1 files changed, 4 insertions(+), 0 deletions(-)[+] [-] Doc/library/readline.rst 4 |
line wrap: on
line diff
--- a/Doc/library/readline.rst
+++ b/Doc/library/readline.rst
@@ -209,6 +209,8 @@ from the user's :envvar:PYTHONSTARTUP
histfile = os.path.join(os.path.expanduser("~"), ".python_history")
try:
readline.read_history_file(histfile)
# default history len is -1 (infinite), which may grow unruly[](#l1.7)
except FileNotFoundError: passreadline.set_history_length(1000)[](#l1.8)
@@ -234,6 +236,7 @@ sessions, by only appending the new hist def save(prev_h_len, histfile): new_h_len = readline.get_history_length()
atexit.register(save, h_len, histfile) @@ -261,4 +264,5 @@ support history save/restore. :: atexit.register(self.save_history, histfile)readline.set_history_length(1000)[](#l1.16) readline.append_history_file(new_h_len - prev_h_len, histfile)[](#l1.17)
def save_history(self, histfile):
readline.set_history_length(1000)[](#l1.24) readline.write_history_file(histfile)[](#l1.25)