multiline strings and proper indentation/alignment
John Salerno
johnjsal at NOSPAMgmail.com
Tue May 9 15:26:12 EDT 2006
Scott David Daniels wrote:
> John Salerno wrote:
>> How do you make a single string span multiple lines, but also allow
>> yourself to indent the second ... without causing the newlines and
>> tabs or spaces to be added to the string as well?
> >
>> self.DTD = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\n
>> "http://www.w3.org/TR/html4/strict.dtd">\n\n'''
>>
>> ..., but I don't want the extra newline or tabs to be a part of the
>> string when it's printed.
>
> The easiest way:
>
> self.DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\n'
> '"http://www.w3.org/TR/html4/strict.dtd">\n\n')
>
> Adjacent strings are combined at compile-time, and parens around allows
> you to do a multi-line expression.
>
> --Scott David Daniels
> scott.daniels at acm.org
Thanks guys. Looks like both of your suggestions are pretty much the
same thing, which is putting strings next to one another. Something
about it looks wrong, but I guess it works!)
More information about the Python-list
mailing list