Variable scope and caller

Mike Meyer mwm at mired.org
Mon Dec 16 14:47:31 EST 2002


Erik Max Francis <max at alcyone.com> writes:
> > One is the Shell-like expansion of variables in a string. The closest
> > you can get to that is %-expansion with a dictionary:
> > 
> >         a = "hello %(b)s"
> >         b = "erik"
> >         print a % globals()
> >         b = "moon"
> >         print a % globals()
> > 
> > will give you the output you asked for.
> I'm thinking you meant locals() in both cases here.

Depends on the context :-). Locals is probably the more correct usage,
though.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list