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