This question is specific to using the python -i
command (not IPython
): how can I limit the exported history to commands from the current session only?
Specifically, when I run Python via terminal (python -i
) and then type the following commands:
from pathlib import Path
x = Path('abc')
from readlines import write_history_file
write_history_file('history.txt')
The exported file contains code from previous Python sessions also, while I am interested only in the code from the current session (in the snippet above this would be the first two commands).