diff --git a/Doc/library/site.rst b/Doc/library/site.rst index e1ca160c107b8b..1f77e65edcd05c 100644 --- a/Doc/library/site.rst +++ b/Doc/library/site.rst @@ -145,10 +145,10 @@ On systems that support :mod:`readline`, this module will also import and configure the :mod:`rlcompleter` module, if Python is started in :ref:`interactive mode ` and without the :option:`-S` option. The default behavior is enable tab-completion and to use -:file:`~/.python_history` as the history save file. To disable it, delete (or -override) the :data:`sys.__interactivehook__` attribute in your -:mod:`sitecustomize` or :mod:`usercustomize` module or your -:envvar:`PYTHONSTARTUP` file. +:envvar:`PYTHONHISTFILE` (or :file:`~/.python_history`, if the former does not +exist) as the history save file. To disable it, delete (or override) the +:data:`sys.__interactivehook__` attribute in your :mod:`sitecustomize` or +:mod:`usercustomize` module or your :envvar:`PYTHONSTARTUP` file. .. versionchanged:: 3.4 Activation of rlcompleter and history was made automatic. diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 457a7fcb6d9e3f..8baf9871259c57 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -515,6 +515,12 @@ before the command-line switches other than -E or -I. It is customary that command-line switches override environmental variables where there is a conflict. +.. envvar:: PYTHONHISTFILE + + If this is the name of a file, and :mod:`readline` is enabled, it will be + used as the history save file. The default is :file:`~/.python_history`. + + .. envvar:: PYTHONHOME Change the location of the standard Python libraries. By default, the diff --git a/Lib/site.py b/Lib/site.py index a065ab0b5db58f..13af684801d881 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -434,8 +434,11 @@ def register_readline(): # each interpreter exit when readline was already configured # through a PYTHONSTARTUP hook, see: # http://bugs.python.org/issue5845#msg198636 - history = os.path.join(os.path.expanduser('~'), - '.python_history') + history = os.environ.get('PYTHONHISTFILE') + if not history or not os.path.isfile(history): + history = os.path.join(os.path.expanduser('~'), + '.python_history') + try: readline.read_history_file(history) except OSError: