heredoc and variables

flupke flupke at nonexistingdomain.com
Fri Jun 4 22:31:49 EDT 2004


Michael Geary wrote:
> 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.
>> 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?
>
> 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]
>
> -Mike

Thanks for the sollution!





More information about the Python-list mailing list