Type of regular expression

J

Joakim Hove

Hello,

I wondered how I could test wether an argument was of type compiled
regexp:

from types import *

def do_something(arg):
if type(arg) is StringType:
print "%s is a string" % arg
elsif type(arg) is RegexpType:
print "%s is a regexp" % arg
else
sys.exit("Argument must be *either* string or regular expression")

which is then called as:

do_something("a string")
do_something(re.compile("^F")

Regards

Joakim

--
/--------------------------------------------------------------------\
/ Joakim Hove / (e-mail address removed) / (55 5) 84076 | \
| Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
| CMU | 5231 Paradis |
\ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 /
\--------------------------------------------------------------------/
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top