import os
import atexit
import readline

history = os.path.join(os.environ["XDG_STATE_HOME"], "python-history")

try:
    readline.read_history_file(history)
except OSError:
    pass

def write_history():
    readline.write_history_file(history)

atexit.register(write_history)
