[IPython-dev] Grab current namespace for magic commands
Mon Mar 21 22:03:42 CDT 2011
I think there is another issue, and that is the status of magic
command in multiline input blocks. Fernando, what is the status of
that type of thing? I think it works fine IIRC.
> At sagedays29, I've been pointed at an issue
> (http://trac.sagemath.org/sage_trac/ticket/10933) where people want to use
> the %time magic command inside a function. However, magic_time evaluates its
> argument in the main user_ns namespace, not the namespace of the function.
I think this does make sense if we are going to allow magics to work
inside functions. Probably have locals be the function's scope and
globals be user_ns?
> I believe it's possible to get the relevant namespace by using
> inspect.stack(). If we do this in interactiveshell.magic(), we can get a
> reference to the frame from which magic() was called, and then evaluate the
> code with the locals and globals of that frame. Does this sound like
> something worth doing, or an awkward kludge? Is there a nicer way to do this
> that I've overlooked?
Sounds good to me as long as multiline magics are working as expected.
> IPython-dev mailing list
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
More information about the IPython-dev