Taking an action on cells after each execution via post_run_cell
and history
from IPython import get_ipython
def summarize_last_cell():
# get the last execution
cell = get_ipython().history_manager.input_hist_parsed[-1]
# print some info about it
print('%s...(%s lines)' % (cell[:4], len(cell.splitlines())))
# register this function to be called after every execution
get_ipython().events.register('post_run_cell', summarize_last_cell)
from...(11 lines)
def foo():
print('hi')
def ...(2 lines)
1
1
1...(1 lines)