Created
July 3, 2020 21:17
-
-
Save Fusion/5b705b9cd1dc882db90b9628bae859e7 to your computer and use it in GitHub Desktop.
Add history management to Python REPL #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def history(numlines = -1): | |
import readline | |
total = readline.get_current_history_length() | |
if numlines == -1: | |
numlines = total | |
if numlines > 0: | |
for i in range(total - numlines + 1, total + 1): | |
print("%3d %s" % (i, readline.get_history_item(i))) | |
def bang(linenum = -1): | |
import readline | |
total = readline.get_current_history_length() | |
if linenum == -1: | |
linenum = total - 1 | |
if linenum > 0: | |
r = readline.get_history_item(linenum) | |
exec(r) | |
readline.replace_history_item(total - 1, r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment