Need formatting suggestion for long strings

Eric Wertman ewertman at gmail.com
Fri Sep 5 16:58:26 EDT 2008


> I'm concerned about the formatting of the string in that I do not want the
> way I split the string up in source code to affect the way the string is
> displayed to the console. In other words, in source, if I break up a single
> string into multiple lines (using carriage returns), I would expect the
> string to still render as a single-line string.
>
> I'm also concerned about the source formatting, because I do not want the
> single-line string to run off the edge of my display. I want it to be in
> "Paragraph form" in the source code, but remain a single-line when printed.

I think you can also escape the line breaks:

>>> mystring = (
...   "This is a very long string that "
...   "spans multiple lines and does "
...   "not include line breaks or tabs "
...   "from the source file between "
...   "the strings partitions.")
>>> mystring2 = 'This is a very long string that spans multiple lines and does not include line breaks or tabs from the source file between the strings partitions.'
>>> mystring == mystring2
True
>>> mystring3 = 'This is a very long string that \
... spans multiple lines and does not include line breaks \
... or tabs from the source file between the strings \
... partitions.'
>>> mystring3 == mystring
True



More information about the Python-list mailing list