assigning multi-line strings to variables

Lie Ryan lie.1296 at
Wed Apr 28 22:17:42 CEST 2010

On 04/29/10 04:16, Alf P. Steinbach wrote:
> On 28.04.2010 18:54, * Lie Ryan:
>> On 04/28/10 15:34, Alf P. Steinbach wrote:
> Yes, that's been mentioned umpteen times in this thread, including the
> *very first* quoted sentence above.
> It's IMHO sort of needless to repeat that after quoting it, and
> providing yet another example right after quoting an example.
> Probably you didn't notice?

I do, my complaints is that you're making it needlessly complex.

>> there is no need to split the string up manually or even
>> scriptically.
> Consider that the concatenation language feature probably is there
> because it's useful (e.g. it preserves indentation and allows per line
> comments).

No, the implicit concatenation is there because Python didn't always
have triple quoted string. Nowadays it's an artifact and triple quoted
string is much preferred. Long dump of text in source code is usually
(or should be) globals constant anyway and you have no problem about
indentation in globals constant. The only ubiquitous place where you
need to put long stream of triple-quoted in non-global is as docstring;
and docstring already handles the problem with indentation.

>> I copied that in less then 10 seconds.
> Doesn't matter how fast it is when it's not correct (or, from another
> point of view, if it doesn't need to be done correctly then it can be
> arbitrarily fast).

It's the nature of the text, who cares about extra line breaks or two.
If this string has been for regex, I'd probably care.

> Of course you can fix it, but since you posted it with errors I think
> you were not aware.

I used triple-quote a lot, and I'm very aware of that.

> In the end there are drawbacks to any way of doing it, so it's to a
> large degree a matter of personal preference, as I see it. I just
> mentioned two additional ways not yet discussed in the thread.
> Exemplifying one of them.

When you have long stream of text and you paste it in source code, it's
usually for one-off scripts that you're too lazy to create a proper file
to read from. You never want to have to do some tedious preprocessing
before you can insert it to the source.

There's never a good reason to insert very long streams of text using
implicit concatenation; not since docstring is here.

More information about the Python-list mailing list