multiline snippets with triple quotes
jeff at ccvcorp.com
Thu Aug 12 22:02:09 CEST 2004
Christoph Zwerschke wrote:
>I sometimes use triple quotes in order to produce snippets of multiline
>code, like that:
>if output == html:
> snip = '''<html>
> <head><title>Hello, World</title></head>
> <body bgcolor="aqua"><h1>What's up?</h1>
> snip = 'Hello!'
>So, what would be the pythonic way to implement such multiline snippets?
IIRC, sequential strings with only whitespace in between them are
automatically concatenated. So the above could be equivalently written as:
if output == html:
snip = "<html>\n"
"<body bgcolor="aqua"><h1>What's up?</h1>\n"
snip = 'Hello!'
This does have the disadvantage of requiring explicit newlines, however.
More information about the Python-list