multi-quoted strings for HERE documents

Michael P. Soulier msoulier at storm.ca._nospam
Mon Nov 18 19:40:45 EST 2002


    Hey people,

    At work I do a mix of Perl and Python. I'm a big fan of the latter.
However, there's one thing that I like in Perl that I haven't quite gotten the
same feel out of Python yet. That would be HERE documents. 

ie. 

print<<EOF;
<table>
    <tr>
        <td>cell contents</td>
    </r>
</table>
EOF

    Now, I can get close in Python with multi-line strings, like so...

print """
<table>
    <tr>
        <td>cell contents</td>
    </r>
</table>"""

    But, there's an initial newline in the output because of where the
beginning quotes are. I can put the quotes on the next line to avoid that...

print \
"""<table>
etc

    But then the block isn't really lined-up the same as the output will look
like. It's a minor thing, I know, but it bugs me. 

    Does anyone have a better way of doing this?

    Mike

-- 
Michael P. Soulier <msoulier at storm.ca>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix
HTML Email Considered Harmful: http://expita.com/nomime.html



More information about the Python-list mailing list