multiline snippets with triple quotes
Christopher T King
squirrel at WPI.EDU
Fri Aug 13 09:22:38 EDT 2004
On Thu, 12 Aug 2004, gohaku wrote:
> Can dedent capture indents or tabs also...
> I noticed that if I do the following:
> snip = '''<html>blah blah
> </html>'''
> Tabs are included with snip.
dedent() will return that string as is, since the <html> tag is already in
the left-most position. If you do something like this, however:
snip = '''\
<html>blah blah
</html>'''
dedent() will flush the <html> tag left, and the </html> tag will be
indented by one tab (since it has a one-tab indent relative to <html>).
> Is there a heredocs (don't know why it's called that) equivalent in
> Python?
AFAIK, triple quotes do everything heredocs do (but with a cleaner
syntax!); the following produce identical output:
bash heredocs:
echo -n <<EOF
Some text.
Woo!
The end.
EOF
Python triple quotes:
print '''\
Some text.
Woo!
The end.'''
More information about the Python-list
mailing list