python: Handle non-existing history file

Create a dummy entry in the history file if it does not exist yet or is
empty. Otherwise `~/.python_history` would be used by site.py.
This commit is contained in:
2022-07-12 17:10:43 +02:00
parent ffaef0fd54
commit 2ac0e01766

View File

@@ -19,6 +19,11 @@ try:
except OSError:
pass
# Create dummy entry if the file does not yet exist, as otherwise
# ~/.python_history is used by site.py
if not readline.get_current_history_length():
readline.add_history("# python history file")
def write_history():
try:
readline.write_history_file(history)