how python interprets re matches
Mike Rennie
mrennie at utm.utoronto.ca
Thu Dec 15 14:51:54 EST 2005
Hi, folks
I'm still relatively new to the language, so I hope this question isn't too
naive. It's a general question for anyone who might have some insights on
Regular Expressions.
According to Mark Pilgrim, author of "Dive Into Python", "If the regular
expression matches, the method will return a Match object, which Python
considers to be true" (Section 16.3, Example 16.8).
So, I think "great", and write a function that returns a match object using
re's.
So i make some testcases. The test where there is no match, and the return from
the function is None, passes.
The test where there is a match, fails on the assertion:
AssertionError: <_sre.SRE_Match object at 0x00AFB9C0> != True
But, shouldn't it accept that as True, based on the info. in Dive Into Python?
I suspect I am being naive in my interpretation of things, so if anyone has any
feedback on how I might get this to work so my function just returns either
True (if a match) or False (if no match), I welcome it.
Cheers,
Mike
--
Michael Rennie
Ph.D. Candidate, University of Toronto at Mississauga
3359 Mississauga Rd. N.
Mississauga, ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie
More information about the Python-list
mailing list