[Python-Dev] String literal concatenation & docstrings

Nick Coghlan ncoghlan at iinet.net.au
Fri Nov 26 15:21:27 CET 2004


A c.l.p question about docstring formatting got me curious about something.

http://www.python.org/doc/2.3.4/ref/string-catenation.html states that:
   Multiple adjacent string literals (delimited by whitespace), possibly using
   different quoting conventions, are allowed, and their meaning is the same as
   their concatenation. Thus, "hello" 'world' is equivalent to "helloworld".

This isn't quite true, since the following doesn't work:

   def some_func():
     """Doc string line 1 (the only line, surprisingly)\n"""
     """Doc string line 2, except it isn't."""

It seems like an odd quirk that the compile-time concatenation of string 
literals doesn't work for docstrings. I had a bit of trawl through the docs and 
the archive with Google, but couldn't find anything that stated whether this 
behaviour was deliberate or accidental.

So, can anyone satisfy my idle curiousity as to whether this was a deliberate 
design choice, or an accident of the implementation?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


More information about the Python-Dev mailing list