Skip to content

Instantly share code, notes, and snippets.

@Stampede
Stampede / pythonTail.py
Created April 4, 2023 12:51
From the interactive Python shell, this will print the last N lines that you entered (default is 50). Useful when you've been working out a problem in the shell and now want to copy & paste the code into your program.
import readline
def history(tail_length=50):
total = readline.get_current_history_length()
for i in range(total - tail_length, total):
print(readline.get_history_item(i + 1))
"""
Meant to be used from the Python interactive shell. The function will print the
last several lines of command history. Default is 50 lines.