Calling %history from python runtime outside of qtconsole

39 Views Asked by At

My desired outcome is to get, similar to what is possible in qtconsole, this type of output:

%hist
import pandas as pd
pd.DataFrame()

But for code run in the python runtime.

I have explored inspect, pdb and traceback but they do not give the clean output of only the code in the __main__ scope.

How would I extract code run in the __main__ or current (eg: only in one function) scope?

I tried hacking around in https://github.com/ipython/ipython/blob/master/IPython/core/magics/code.py and doing stuff like:

import IPython.core.magics.code as magic_code
c = magic_code.CodeMagics()
c.save(parameter_s='%hist')

but to no avail. Thanks for any guidance.

0

There are 0 best solutions below