replace %(word) in a string

Peter Hansen peter at engcorp.com
Wed Sep 17 14:22:41 EDT 2003


Peter Hansen wrote:
> 
> Fred Pacquier wrote:
> >
> > Mirko Zeibig <mirko-lists at zeibig.net> said :
> >
> > > Especially useful together with the locals() function, which returns a
> > > dictionary of locally defined variables:
> > >
> > > def foo():
> > >     a = "Hello"
> > >     b = "World"
> > >     print "%(a)s %(b)s" % locals()
> >
> > Yes, that's a wonderful feature. Recently though, I've wondered a couple of
> > times : is there an easy way to substitute with both local AND global
> > variables ?...
> 
> tempDict = locals()
> tempDict.update(globals())

Hmmm... should that be locals().copy() ?  Probably...




More information about the Python-list mailing list