Skip to content

Instantly share code, notes, and snippets.

@jasonmorganson
Created December 14, 2022 21:48
Show Gist options
  • Save jasonmorganson/fd07c7e6cd534071a7521a66f5c5baa3 to your computer and use it in GitHub Desktop.
Save jasonmorganson/fd07c7e6cd534071a7521a66f5c5baa3 to your computer and use it in GitHub Desktop.
import os
if 'PYTHONHISTFILE' in os.environ:
history = os.path.expanduser(os.environ['PYTHONHISTFILE'])
elif 'XDG_DATA_HOME' in os.environ:
history = os.path.join(os.path.expanduser(os.environ['XDG_DATA_HOME']), 'python', 'python_history')
else:
history = os.path.join(os.path.expanduser('~'), '.python_history')
history = os.path.abspath(history)
_dir, _ = os.path.split(history)
os.makedirs(_dir, exist_ok=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment