From: goldtech on
Hi,

This is undoubtedly a newbie question. How doI assign variables
multiline strings? If I try this i get what's cited below. Thanks.


>>> d="ddddd
ddddd"
>>> d
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
NameError: name 'd' is not defined
From: Brendan Abel on
On Apr 27, 7:20 pm, goldtech <goldt...(a)worldpost.com> wrote:
> Hi,
>
> This is undoubtedly a newbie question. How doI assign variables
> multiline strings? If I try this i get what's cited below. Thanks.
>
> >>> d="ddddd
> ddddd"
> >>> d
>
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> NameError: name 'd' is not defined



d = "ddddddddd"\
"ddddd"

or

d = "dddddddddd\
dddddd"

You don't need the trailing slash in the first example if you are
writing this in a script, python assumes it.
From: MRAB on
goldtech wrote:
> Hi,
>
> This is undoubtedly a newbie question. How doI assign variables
> multiline strings? If I try this i get what's cited below. Thanks.
>
>
>>>> d="ddddd
> ddddd"
>>>> d
> Traceback (most recent call last):
> File "<interactive input>", line 1, in <module>
> NameError: name 'd' is not defined

Use a triple-quoted string literal:

>>> d = """ddddd
.... ddddd"""
>>> d
'ddddd\nddddd'
From: goldtech on
On Apr 27, 7:31 pm, Brendan Abel <007bren...(a)gmail.com> wrote:
> On Apr 27, 7:20 pm, goldtech <goldt...(a)worldpost.com> wrote:
>
> > Hi,
>
> > This is undoubtedly a newbie question. How doI assign variables
> > multiline strings? If I try this i get what's cited below. Thanks.
>
> > >>> d="ddddd
> > ddddd"
> > >>> d
>
> > Traceback (most recent call last):
> >   File "<interactive input>", line 1, in <module>
> > NameError: name 'd' is not defined
>
> d = "ddddddddd"\
>     "ddddd"
>
> or
>
> d = "dddddddddd\
> dddddd"
>
> You don't need the trailing slash in the first example if you are
> writing this in a script, python assumes it.

Thanks but what if the string is 500 lines. Seems it would be hard to
put a "\" manually at the end of every line. How could i do that?
From: goldtech on
On Apr 27, 7:33 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
> goldtech wrote:
> > Hi,
>
> > This is undoubtedly a newbie question. How doI assign variables
> > multiline strings? If I try this i get what's cited below. Thanks.
>
> >>>> d="ddddd
> > ddddd"
> >>>> d
> > Traceback (most recent call last):
> >   File "<interactive input>", line 1, in <module>
> > NameError: name 'd' is not defined
>
> Use a triple-quoted string literal:
>
>  >>> d = """ddddd
> ... ddddd"""
>  >>> d
> 'ddddd\nddddd'

Only seems to work when there's a '... ' on the 2nd line. I need a way
to assign large blocks of text to a variable w/out special formatting.
Thanks.