text processing: variable interpolation and more

Oleg Broytmann phd at phd.pp.ru
Sun Sep 9 01:37:54 EDT 2001


On Sun, Sep 09, 2001 at 05:03:52AM +0000, Greg Weeks wrote:
> def print_form_letter(recipient, they_want_us):
>     render(sys.stdout, '''\
> Dear <recipient>:
> 
> We are pleased to hear that you have chosen BigCorp.|?        they_want_us
> We are sorry to hear that you will not be using BigCorp.|?    not they_want_us
> 
> Our company is the best in its class, blah, blah, blah.
> 
> Sincerely yours,
> Brad Majors, BigCorp Marketing
> ''', globals(), locals())

print "Dear %(recipient)s:" % dict

   will extract dict[recipient] and put it into the string as string. More
details in Python docs about overloaded operator %.

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list