RFC PEP candidate: q'<delim>'quoted<delim> ?

Terry Reedy tejarex at yahoo.com
Thu Mar 7 13:46:03 EST 2002


"Bengt Richter" <bokr at oz.net> wrote in message
news:a67ehl$uhi$0 at 216.39.172.122...
> How does it seem if you go along the steps I took?:
>
>  1. You have an arbitrary sequence of characters that are to be
>  the value of a string.
>  2. The sequence may contain both ''' and """ and may even end
>  with \ and it must be unchanged.
>  3. (2) Means you need a different delimiter than " or ' or """ or
'''.

Since (3) does not follow from (2), it seems like this proposal is
unnecessary.  Strings read from a file (this includes raw_input() from
users) already meet desiderata 1 and 2.

>>> s=raw_input('Hi: ')
Hi: Python delimiters include ', ", ''', """, and \
>>> print s
Python delimiters include ', ", ''', """, and \

 In the extremely rare case in which one really *needs* all 4 string
delimiters within a single string and the string *must* get its value
from a programmer-writter string literal rather than a file, one can
use octal escapes (or \\ for \).

>>> print """Python's string delimiters are ', ", ''', and
\042\042\042."""
Python's string delimiters are ', ", ''', and """.
>>> print '''Python's string delimiters are ', ", \047\047\047, and
""".'''
Python's string delimiters are ', ", ''', and """.

Terry J. Reedy










More information about the Python-list mailing list