[Python-Dev] Why both r'' and R'', u'' and U''?

Guido van Rossum guido@python.org
Sun, 14 Jan 2001 12:08:28 -0500


> Ka-Ping Yee wrote:
> > 
> > Sorry i'm being forgetful -- could someone please refresh my memory:
> > 
> > Was there a good reason for allowing both lowercase and capital 'r'
> > as a prefix for raw-strings?  I assume that the availability of both
> > r'' and R'' is what led to having both u'' and U''. 
> 
> Right.
> 
> > Is there any
> > good reason for that either?
> 
> No idea... I have never used anything other than the lowercase
> versions.

It comes from the numeric literals.  C allows 0x0 and 0X0, and 0L as
well as 0l.  So does Python (and also 0j == 0J).

> > This just seems to lead to ambiguity and unneeded complexity:
> > more cases in tokenize.py, more cases in tokenize.c, more work
> > for IDLE, more annoying when searching for u' in your editor.
> > (I was about to fix the lack of u'' support in tokenize.py and
> > that made me think about this.)
> > 
> > What happened to TOOWTDI?
> > 
> > Would you believe we now have 36 different ways of starting a string:
> > 
> >     '      "      '''    """
> >     r'     r"     r'''   r"""
> >     u'     u"     u'''   u"""
> >     ur'    ur"    ur'''  ur"""
> >     R'     R"     R'''   R"""
> >     U'     U"     U'''   U"""
> >     uR'    uR"    uR'''  uR"""
> >     Ur'    Ur"    Ur'''  Ur"""
> >     UR'    UR"    UR'''  UR"""
> >
> > Would it be outrageous to suggest deprecating the last five rows?
> 
> No. + 1 on the idea.

Why bother?  All that does is outdate a bunch of documentation.  I
don't see the extra effort in various parsers as a big deal.

--Guido van Rossum (home page: http://www.python.org/~guido/)