Last active
December 15, 2015 15:49
-
-
Save seumasmorrison/5284208 to your computer and use it in GitHub Desktop.
Example of how to query IPython history, searching using a known string used in a session and then using the session_id from the first query to get the whole of that session.
This file contains 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
#Example of searching for a string in IPython sqlite history | |
from IPython.core.history import HistoryAccessor | |
history_accessor = HistoryAccessor() | |
sqlite_cursor = history_accessor.search('*threshold*') | |
results = sqlite_cursor.fetchall() | |
for result in results: | |
print result | |
#From the first number in the printed results you can see the relevant session | |
#number, and then below retrieve the whole session using get_range | |
session_results = history_accessor.get_range(1321) | |
for session, line_number, command in session_results: | |
print command | |
#Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment