replace %(word) in a string

Fred Pacquier xnews at
Wed Sep 17 18:30:08 CEST 2003

Mirko Zeibig <mirko-lists at> 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 ?...


More information about the Python-list mailing list