test for raw string

J

John Hunter

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

Thanks,
John Hunter
 
D

Duncan Booth

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.
 
P

Paul Rubin

John Hunter said:
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

func(r'\hi mom') # do_x
func('hi mom') # do_y

No. Those are just two different ways of writing the same string.
It's like asking func(3.0) and func(3.00) to do two separate things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top