Saki Shinoda

Machine learning engineer based in London, UK.

Home
About
Blog

Rescue lost code in Jupyter/IPython notebooks

2016-07-24 10:00:00 +0000

I found this in a moment of great need here. It explains it far better than I do so go check it out. In short though, to rescue a function that is still in your environment, but that you defined in a cell that you’ve since deleted, use the following nifty little function.

def rescue_code(function):
    import inspect
    get_ipython().set_next_input("".join(inspect.getsourcelines(function)[0]))