Multiline strings and indentation

donotspam-jen@personic.com dnotspam-jen at personic.com
Mon Jul 17 21:26:58 EDT 2000


Umm, yes to everyone who replied. But ... that's quite a few more keystrokes
to add.

It's a little less work to use parentheses:

print ("the first line of text\n"
       "the second line of text \n"
       "the third line ... \n")

But in both cases you have to put in extra quotes and explict newline
characters (unless you don't care where the text wraps). Multi-line strings
save a bit of typing, and are a bit easier to reformat when editing. So I
guess this means I have to choose between weird indentation (multi-line
strings) or typing more characters?

Jen

"j vickroy" <jvickroy at sec.noaa.gov> wrote in message
news:39736E71.AE8B128B at sec.noaa.gov...
> How about:
>
> >>> print "this" + \
>                 " is" + \
>                 " a" + \
>                 " long" + \
>                 " string"
>
> this is a long string
> >>>
>
> "donotspam-jen at personic.com" wrote:
>
> > I'm just getting started with Python. The indentation feature really
does
> > make things readable ... except when using multi-line strings.  This
just
> > doesn't look right:
> >
> > def multiline(x):
> >   if x:
> >     print """this is a
> > multi-line string that spans
> > three lines"""
> >  print "another string"
> >
> > Is there a way to make the above more readable? It would be nice if it
could
> > be written this way and have Python just figure out what whitespace to
> > ignore:
> >
> > def multiline(x):
> >   if x:
> >     print """this is a
> >              multi-line string that spans
> >              three lines"""
> >  print "another string"
> >
> > Thanks for any suggestions!
> >
> > Jen
>





More information about the Python-list mailing list