On Sun, Sep 26, 2010 at 4:21 PM, Hugo Arts <hugo.yo...@gmail.com> wrote:

> On Sun, Sep 26, 2010 at 10:16 PM, Rance Hall <ran...@gmail.com> wrote:
> > My app will be printing a series of documents that are the same each
> > time the doc is printed with the exception of the variables.  Sort of
> > a MailMerge if you will.
> >
> >
>
> I would suggest you take a look at string.Template or the str.format
> method. It may be somewhat simpler than doing a whole lot of replaces,
> perhaps faster as well.
>
> http://docs.python.org/library/string.html#template-strings
> http://docs.python.org/library/stdtypes.html#str.format
>
> Hugo
>
> I agree.   I had a great deal of success with using docstrings along with
str.format in a program I wrote at work.

Example, two ways:

"""
Dear Mr. {0},

Thanks for your recent inquiry.

Your current invoice #{1} is overdue by {2} days.

Please make remittance by {3} in order to avoid
overdue fees.

Sincerely,
{4}
Billing Dept.
""".format(client_name, inv_num, num_days, due_date, sender)

or

over_due_notice = """

Dear Mr. {0},

Thanks for your recent inquiry.

Your current invoice #{1} is overdue by {2} days.

Please make remittance by {3} in order to avoid
overdue fees.

Sincerely,
{4}
Billing Dept.
"""

over_due_notice.format(client_name, inv_num, num_days, due_date, sender)
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to