string interpolation with both local and module variables?

Graham Guttocks graham_guttocks at yahoo.co.nz
Wed May 2 19:07:32 CEST 2001


Alex Martelli <aleaxit at yahoo.com> wrote: 

> Just change the second line of printmsg() to:
> 
>        message = makemessage('/tmp/test.txt', vars())
> 
> and makemessage() itself to, for example:
> 
>    def makemessage(file, vardict):
>        fp = open(file)
>        template = fp.read()
>        import Defs
>        localdict = Defs.__dict__.copy()
>        localdict.update(vardict)
>        text = template % localdict
>        return text

Perfect.  Thanks again Alex!

Cheers,
Graham

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/




More information about the Python-list mailing list