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: # <- This constant does not
# exist, it is only
# something I invented.
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 /
\--------------------------------------------------------------------/
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: # <- This constant does not
# exist, it is only
# something I invented.
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 /
\--------------------------------------------------------------------/