test for raw string

Duncan Booth me at privacy.net
Wed Feb 25 18:18:09 CET 2004

John Hunter <jdhunter at ace.bsd.uchicago.edu> wrote in 
news:mailman.111.1077726871.8594.python-list at python.org:

> 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
> def func(s):
>     if israw(s): do_x()
>     else: do_y()
> func(r'\hi mom')  # do_x
> func('hi mom')    # do_y

A raw string is a feature of the syntax at compile time. You cannot 
distinguish a raw string any more than you can distinguish "hi mom" and 'hi 
mom'. The type of quotes, whether it was single or triple quoted, and 
whether it was raw or normal are simply aspects of the syntax.

More information about the Python-list mailing list