heredoc and variables

Peter Otten __peter__ at web.de
Fri Jun 4 17:36:31 CEST 2004


flupke wrote:

> 2) Consider following heredoc
> 
> end_html="""</BODY>
> </HTML>"""
> 
> I have to write it like this to avoid having an empty line added above
> AND below the actual string when using it.

Why would you care about whitespace in HTML?

> So this would produce the extra empty lines
> 
> end_html="""
> </BODY>
> </HTML>
> """
> 
> I actually think that the last piece of code is more readable. Is there
> a way to stop that behaviour or is there a kind of trim function i
> can apply to get rid of the 2 extra lines?


>>> print """\
... here's how \
... to escape \
... newlines"""
here's how to escape newlines
>>>

Peter




More information about the Python-list mailing list