test for raw string

Terry Reedy tjreedy at udel.edu
Wed Feb 25 12:14:54 EST 2004


"John Hunter" <jdhunter at ace.bsd.uchicago.edu> wrote in message
news:m2k72b16lc.fsf at mother.paradise.lost...
>
> I have a function that takes a string as an argument.  Is there a way
> to test whether the caller of this function passed in a raw string

No, because there is no such thing (object) as a raw string.  There are
only str strings and unicode strings. The phrase 'raw string' is an
abbreviation of 'raw string literal'.  The 'r' prefix changes how the
interpreter interprets the literal text (by not interpreting '\' as
special) when creating the string (of either type).  And that is it.

>>> type('s') == type(r's')
1
>>> type(u's') == type(ur's') # ru's' does not work
1

Terry J. Reedy









More information about the Python-list mailing list