how python interprets re matches

M

Mike Rennie

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
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top