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

Bengt Richter bokr at oz.net
Thu Mar 7 19:36:39 EST 2002


On Thu, 07 Mar 2002 18:46:03 GMT, "Terry Reedy" <tejarex at yahoo.com> wrote:

>
>"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.
>
Sorry, I wasn't making clear an unspoken condition I really had in mind ;-)
I think (3) does follow (2) using the added explicit condition that the
text quotation is to be part of the source text of a program or module,
and the quoted text must not need to be changed or restricted to do it.

>>>> s=raw_input('Hi: ')
>Hi: Python delimiters include ', ", ''', """, and \
>>>> print s
>Python delimiters include ', ", ''', """, and \
>
This violates my unspoken condition, but certainly i/o can get you whatever.

> 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 \).
>
This also violates the unspoken condition ;-)
The problem to solve is not constructing an arbitrary-valued string
by writing an escaped sequence adhering to current python string syntax.
That can be done, as you show.

The problem is to do it by using an existing source of text, without
changing the text, and without using an external file to delimit it.

The simplest practical example is wanting to use a paste operation
to insert arbitrary text into a program source without having to inspect
the text or modify it, yet be able to use it to define a string
with the exact raw text value.

Show me how to do that, and I'll be convinced there is no need for
string-delimited quotation.

>>>> 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 """.
>
Sorry for not being clear. I guess that's what this discussion process
is for. It's clarifying the issues for me too ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list