Skip to content

Instantly share code, notes, and snippets.

@berdario
Created February 10, 2016 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berdario/640b3ab00b128fdf3338 to your computer and use it in GitHub Desktop.
Save berdario/640b3ab00b128fdf3338 to your computer and use it in GitHub Desktop.
[dario@archvm ~]$ python
Python 3.5.1 (default, Dec 7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+2
4
>>>
[dario@archvm ~]$ env PYTHONSTARTUP=a.py python
Python 3.5.1 (default, Dec 7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 3+3
6
>>>
[dario@archvm ~]$ env PYTHONSTARTUP=a.py python
Python 3.5.1 (default, Dec 7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> readline.get_current_history_length()
17
>>> [readline.get_history_item(x) for x in [14,15,16]]
['locale.getlocale()', '2+2', 'import readline']
>>>
[dario@archvm ~]$ cat /etc/os-release
NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
@Lekensteyn
Copy link

I observe different behavior, the history file is always written for some reason:

~peter@al:~$ cat .python_history
cat: .python_history: No such file or directory
~peter@al:~$ cat /tmp/a.py
import readline, atexit, sys
sys.__interactivehook__()
atexit.unregister(readline.write_history_file)
~peter@al:~$ PYTHONSTARTUP=/tmp/a.py python
Python 3.5.1 (default, Dec  7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+1
2
>>>
~peter@al:~$ cat /tmp/a.py
import readline, atexit, sys
sys.__interactivehook__()
atexit.unregister(readline.write_history_file)
~peter@al:~$ cat .python_history
1+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment