Quoting quotes

Grant Edwards invalid at invalid.invalid
Fri Feb 26 16:04:04 CET 2010


On 2010-02-26, Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
> On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote:
>
>> But the first method doesn't run correctly :
>> 
>> 
>>>>> print """The play "All's Well That Ends Well""""
>>   File "<stdin>", line 1
>>     print """The play "All's Well That Ends Well""""
>>                                                    ^
>> SyntaxError: EOL while scanning single-quoted string
>>>>>
>>>>>
>> 
>> Any comment ?
>
> Of course not. Quotes can't be nested, so the first time the
> parser hits three quote marks, you have reached the end of the
> string. You then open a new string with a single quote mark,
> and then fail to close it. Hence the EOL while scanning a
> single-quoted string.

IMO, the error message is misleading to many people, since in
many/most contexts the term "single-quoted" refers to this:

  'here is a single quoted string'

And not this:

  "this is a double-quoted string"

-- 
Grant Edwards                   grante             Yow! And then we could sit
                                  at               on the hoods of cars at
                               visi.com            stop lights!



More information about the Python-list mailing list