How to do this in Python...

Aahz aahz at pythoncraft.com
Thu Jan 23 22:09:52 EST 2003


In article <mailman.1043361749.31477.python-list at python.org>,
Skip Montanaro  <skip at pobox.com> wrote:
>
>    Mike> match = re.match(pattern, string)
>    Mike> if match:
>    Mike>   // do something with match object
>
>Verbose or not, this is approximately the correct way to do it.  You should
>test against None, and eschew the C++ comments:
>
>    match = re.match(pattern, string)
>    if match is not None:
>      # do something with match object

That seems a bit odd to me.  Why test against None, instead of simply
"if not match"?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach




More information about the Python-list mailing list