0

I want to add a function like this:

def history():
  import readline
  for i in range(readline.get_current_history_length()):
    print (readline.get_history_item(i + 1))

so that whenever I'm in a Python shell (like running python3) or if I hit a breakpoint using ipdb in Python code, that I can just call history().

Where do I add this code? (MacOS)

Michael
  • 776
  • 4
  • 19
  • Does this answer your question? [how do you see the entire command history in interactive python?](https://stackoverflow.com/questions/6558765/how-do-you-see-the-entire-command-history-in-interactive-python) – agtoever Dec 31 '19 at 07:57
  • I have the function already, but I'm trying to figure out where I can add this code so that I don't have to write the function everytime – Michael Dec 31 '19 at 18:21

1 Answers1

0

You might be able to achive that using the PYTHONSTARTUP env var.
Create a script that contains this code, and export the variable to your shell's profile

https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP

Ron Serruya
  • 3,988
  • 1
  • 16
  • 26