[Python-ideas] Python 2's re module should take longs

Antoine Pitrou solipsis at pitrou.net
Wed Oct 1 11:03:56 CEST 2014


On Wed, 1 Oct 2014 10:51:57 +1000
Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, Sep 30, 2014 at 09:57:44PM +0200, Antoine Pitrou wrote:
> > On Tue, 30 Sep 2014 12:16:13 -0500
> > Ryan Gonzalez <rymg19 at gmail.com> wrote:
> > > This works:
> > > 
> > > re.search('(abc)', 'abc').group(1)
> > > 
> > > but this doesn't:
> > > 
> > > re.search('(abc)', 'abc').group(1L)
> > > 
> > > The latter raises "IndexError: no such group". Shouldn't that technically
> > > work?
> > 
> > Yes, it's a bug.  Feel free to open an issue.
> 
> I'm not so sure that it's a bug. Should .group(1.0) work? That also is 
> numerically equal to 1.

It's not about them being numerically equal, it's about them being
integers (interchangeable, as Guido points out).

We have been fixing many such bugs over the years.

> So this is a long-established restriction on the argument.

Please don't try to second-guess the documentation when deciding what
is a "long-established restriction".

Regards

Antoine.




More information about the Python-ideas mailing list