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

Bengt Richter bokr at oz.net
Fri Mar 8 18:29:03 EST 2002


On Fri, 08 Mar 2002 04:57:10 GMT, Joshua Macy <l0819m0v0smfm001 at sneakemail.com> wrote:

>Greg Ewing wrote:
>
>> I have another idea that doesn't suffer from that
>> problem.
>> 
>>   def string my_string:
>>     This is a free-form string constant. Its value consists
>>     of all the text at this indentation level, verbatim,
>>     with the indentation stripped off. It can contain
>>     ', ", ''', """, \ or any other characters.
>> 
>> 
>
>
>But then you have to indent everything in the text to that level, which 
>isn't quite the same as cut-and-paste arbitrary text any more.  Granted, 
>it's not hard to do with a good editor, but neither is escaping a 
>whatever triple quotes you might find in the text (even Notepad can do 
>that).
>
>For that matter, the PEPs to make Python more unforgiving of what's 
>contained in strings (only valid declared encodings or binary as octal 
>escape sequences) seem to be advancing rapidly, so schemes for stuffing 
>more arbitrary and unexamined junk into the source code seem to be
>heading in the wrong direction.
>
This is an interesting aspect. My example of pasting text into a current source
really should take into account the encoding of both the text to be pasted and the
destination context. I.e., ISTM a conversion to whatever the current internal representation
of the destination was should be done (which might raise an exception), followed by
conversion for display purposes (which might also raise an exception in the context
of a raw string, where unprintable characters can't be used! See my other post for
some weirdness re current r'strings').


>I guess I don't really see the motivation for the proposed feature.  If 
>triple quoting isn't sufficient, I'd take that as a sign that the 
>material should be a separate data file...it's not like Python makes it 
>hard to read an external file into a string.
>
No, but they are hard to see when you are reading code that just does i/o,
and if you have dozens of snippets, that would be a lot of files. Of course,
you could put them in a multipart MIME formatted file with, ahem, delimiters
between the pieces ;-)




More information about the Python-list mailing list