Quoting quotes

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Feb 26 14:43:43 CET 2010


On Fri, Feb 26, 2010 at 7:29 AM, candide <candide at free.invalid> wrote:

> Suppose you have to put into a Python string the following sentence :
>
> The play "All's Well That Ends Well" by Shakespeare
>
> It's easy do it :
>
> >>> print """The play "All's Well That Ends Well" by Shakespeare"""
> The play "All's Well That Ends Well" by Shakespeare
>
> Now, change the sentence to this one :
>
> The play "All's Well That Ends Well"
>
> Using triple single quotes works fine
>
> >>> print '''The play "All's Well That Ends Well"'''
> The play "All's Well That Ends Well"
>
>
> 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 ?
>
>
>

You have 4 quotes at the end of the line instead of 3. So the first 3 close
the long quote and then the 4th opens a new quote which doesn't get closed.


> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100226/bd306df1/attachment.html>


More information about the Python-list mailing list