#!/usr/bin/env python # coding: utf-8 # Taking an action on cells after each execution via `post_run_cell` and history # In[11]: 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) # In[12]: def foo(): print('hi') # In[13]: 1