[IPython-user] pysh variable substituion and scope

Krishna Mohan Gundu gkmohan at gmail.com
Sun Jun 4 16:47:44 CDT 2006


> > Right now I'm not really sure how to do that correctly, and it would
> > have to be done (I think) in Itpl's interpolation code.  I thought of
> > walking the stack (the f_back attributes let you do this easily), but
> > you'd need to be sure to stop before hitting ipython's own frames, to
> > avoid ipython's internal variables from being interpolated out.  It's
> > a tricky problem, and given that the language's own machinery already
> > does this correctly, I think it's saner to simply let Python deal with
> > it.
>
> We cannot do frame backtracking in Itpl since the IPSHELLs execution
> stack, so to say, is intervened by call to ipsystem(), which is
> executed in a different namespace. Which means Itpl needs to know more
> information than it ideally should. I think the right place for it is
> ipsystem(). Currently I used a signature to identify the global
> namespace of IPSHELL by setting the variable __sig__ in __builtins__.
> I used the value 0xa005 because I vaguely remember that's the
> signature for boot-sector. One can then backtrack until one exits the
> global namespace identified by this signature. In case of embedding
> one needs to set/verify signature in appropriate namespace. I dont
> know if this solves the problem in general (not likely), since I am
> simply merging/overriding the locals from every frame. I will read the
> scoping rules of various code blocks and modify it appropriately in
> future.

Since merging locals is a costly function, I think one should try
ip.system() first without any merging and only on catching NameError
should one proceed with merging and retry ip.system().




More information about the IPython-user mailing list