Yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/readline-example.html

From ZCubes Wiki
Revision as of 19:59, 7 November 2013 by MassBot1 (talk | contribs) (Created page with "<div class="navigation"> {| width="100%" cellspacing="2" align="center" | yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-readline.html|[[Image:yurt...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


7.17.1 Example

The following example demonstrates how to use the readline module's history reading and writing functions to automatically load and save a history file named .pyhist from the user's home directory. The code below would normally be executed automatically during interactive sessions from the user's $PYTHONSTARTUP file.

import os
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
    readline.read_history_file(histfile)
except IOError:
    pass
import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile

See About this document... for information on suggesting changes.