[Python-ideas] Custom string prefixes

Ned Batchelder ned at nedbatchelder.com
Mon May 27 18:59:40 CEST 2013


On 5/27/2013 11:51 AM, Haoyi Li wrote:
> If-if-if all that works out, you would be able to /completely remove 
> /the/(/"b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | 
> "RB" | "r" | "u" | "R" | "U") from the grammar specification! Not add 
> more to it, remove it! Shifting the specification of all the different 
> string prefixes into a user-land library. I'd say that's a pretty 
> creative way of getting rid of that nasty blob of grammar =D.
>

In order to achieve this ideal, and assuming you'd be keeping backward 
compatibility (!), you'd have to explain how to support both of these 
strings:

     "Hello\n"
     r"Hello\n"

Implicit in your idea is that the plain literal creates a string of some 
kind, and but the r-prefixed string would apply some user-land function 
to the string.  But there is no function you can apply to string 
literals to make them be raw.  The r prefix suppresses interpretation 
that happens in un-prefixed strings.  By the time a user-land function 
got hold of the string, the interpretation has already been done, 
information has already been lost.

--Ned.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130527/ef180e32/attachment.html>


More information about the Python-ideas mailing list