[Python-Dev] String literal concatenation & docstrings
Nick Coghlan
ncoghlan at iinet.net.au
Fri Nov 26 16:19:10 CET 2004
Michael Hudson wrote:
> Nick Coghlan <ncoghlan at iinet.net.au> writes:
> I haven't actually checked or anything rash like that, but I'd imagine
> the answer is something like:
>
> The two strings are separate statements as far as the parser is
> concerned, and the "concatenating adjacent strings" thing only
> happens within an expression.
That would certainly be a sensible explanation. The only time I've ever actually
made use of the feature is when assigning a long string, and even then only
rarely (I'm more likely to use triple quotes and left align the whole thing)
> You can do this:
>>>>"con"\
>
> ... "cat"
> 'concat'
Which actually does work for combining multiple strings into a single docstring.
>>So, can anyone satisfy my idle curiousity as to whether this was a
>>deliberate design choice, or an accident of the implementation?
>
> Well, it surprises me not at all.
I think the key distinction I'd missed was that in the doc string case, the two
strings were actually separate statements. Once that distinction is noted, the
behaviour is, as you say, unsurprising. It also makes it obvious why escaping
the newline has the effect it does.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-Dev
mailing list