[Tutor] inserting variables into a docstring

Bill Allen wallenpb at gmail.com
Sun Aug 22 06:49:05 CEST 2010

On Sat, Aug 21, 2010 at 11:27 PM, Hugo Arts <hugo.yoshi at gmail.com> wrote:

> The variable is inserted just fine for me, though there's some
> problems with the <a> tag, because you shouldn't surround GET
> variables with quotation marks, e.g. you should do this:
> http://example.com/?ecn=423434
> NOT this:
> http://example.com/?ecn="423434"
> If you do this, the HTML parser will encounter the first ", think that
> it's come to the end of the href="" attribute, and ignore the rest.
> But that's an HTML issue, not a python one.
> As an aside, consider using string formatting operations like so:
> newMail.HTMLBody = """
> <pre>
> ECN number {0} on Project {1} has been closed.
> Below is a link to the ECN on the intranet.
> <a href="http://web_server_at_work.com/cgi-bin/part-url.cgi?ecn={0}<http://web_server_at_work.com/cgi-bin/part-url.cgi?ecn=%7B0%7D>
> ">{0}</a>
> ECN Description:
> {2}""".format(pecn, pecn_project, pdesc)
> Hugo,

Thank you for the reminder of the problem with the HTML.  I see that now.
You are right, however, using that format method works wonderfully and is
definitely the way to go!   I see how I can apply that in lots of ways.

Thanks for the help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100821/65cc7ddf/attachment.html>

More information about the Tutor mailing list