Skip to main content
6 of 15
what it actually does

Here's my method (which turned out to be basically a more reliable and pythonic version of berdario's method). It only disables writing to .python_history, but not reading from it if it exists, or appending new lines to the current instance's history. I recommend saving it as site-packages/sitecustomize.py, because site is the module that both writes to .python_history and imports sitecustomize if it exists, although naming it something else and pointing to it with PYTHONSTARTUP works too.

import sys
import readline
import atexit
oldhook = sys.__interactivehook__
def newhook():
    oldhook()
    atexit.unregister(readline.write_history_file)
sys.__interactivehook__ = newhook