[IPython-dev] Grab current namespace for magic commands
Mon Mar 21 21:35:45 CDT 2011
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 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev