heredoc and variables

Michael Geary Mike at DeleteThis.Geary.com
Sat Jun 5 04:19:45 EDT 2004


> Michael Geary wrote:
> > If you can live with the newline at the end of the text
> > (which in most cases is what you want anyway), this
> > is the cleanest way to do it:
> >
> > end_html = """\
> > </BODY>
> > </HTML>
> > """
> >
> > Or, you can get rid of both newlines this way:
> >
> > end_html = """
> > </BODY>
> > </HTML>
> > """[1:-1]

flupke wrote:
> Thanks for the sollution!

De nada.

Now that I think of it, if you do want to get rid of both newlines, here are
a couple of other ways to do it:

end_html = """\
</BODY>
</HTML>\
"""

That is a bit ugly, but this seems reasonable (and better than the [1:-1]
slice trick):

end_html = """\
</BODY>
</HTML>"""

-Mike





More information about the Python-list mailing list