def extract_vars(*names,**kw):

    depth = kw.get('depth',0)
    
    callerNS = sys._getframe(depth+1).f_locals
    return dict((k,callerNS[k]) for k in names)
Extract a set of variables by name from another frame.
dataset/ETHPy150Open ipython/ipython-py3k/IPython/utils/frame.py/extract_vars