test for raw string
Dave Brueck
dave at pythonapocrypha.com
Wed Feb 25 11:47:21 EST 2004
John wrote:
> 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
>From your program's point of view, I don't think there _is_ such a thing as a
raw string. Consider:
>>> r'dave' is 'dave'
True
>>> r'dav\e' is 'dav\\e'
True
It's merely a convenience thing for us humans. Why would your program care
though (what are you trying to do)?
-Dave
More information about the Python-list
mailing list