7.17.1 Example
Keywords: lib

##
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