groups method of the math object (was Re: Perl is worse!)

Alex Martelli alex at magenta.com
Sun Jul 30 11:57:03 EDT 2000


"Karl Ulbrich" <kulbrich at yahoo.com> wrote in message
news:20000730023357.A3193 at exeter.exeter.org...
    ...
> >     I don't see where I can tell it to pass something other than None on
a
> > match.  The docs I read, (not here) state that it /will/ return None on
a
> > no-match, not that it /can/ and that you can override it.
>
> I don't see it either (Alex?) in the library reference.  Personally

It's in 4.2.5 in the Library Reference I have here, "4.2.5 Match Objects"
to be precise:

groups ([default])
Return a tuple containing all the subgroups of the match, from 1 up to
however many groups are in the pattern. The default argument is used for
groups that did not participate in the match; it defaults to None.

> I thought both the 'int(x or 0)' approach and the function Alex suggested
> were good ways to establish problem-specific default values, especially
> since '0' isn't always an apprpriate default.

I agree, and int(x or whatever) is more general since it works with any
x that is a possibly-empty-sequence-of-digits (the 'whatever' default
will more often be 1, I think; if you specify you want something, without
explicitly specifying how many of those somethings you want, it's more
natural to default to you wanting one of them, than none).


Alex






More information about the Python-list mailing list