[issue29965] MatchObject __getitem__() should support slicing and len

Michael Selik report at bugs.python.org
Mon Apr 3 14:09:54 EDT 2017


Michael Selik added the comment:

Sorry, it looks like I got the issue number wrong. My comparison should not have been with #24454, but instead with an issue I can't locate at the moment. Reproducing the example:

    for g0, g1, g2 in re.finditer(r'(\d+)/(\d+)', 'Is 1/3 the same as 2/6?'):
        ratio = Fraction(int(g1), int(g2))

Better:

    for mo in re.finditer(r'(\d+)/(\d+)', 'Is 1/3 the same as 2/6?'):
        ratio = Fraction(*map(int, mo[1:3]))

The map in the last one isn't very pretty, but I hope it illustrates the gist of what I'd like to do for a much larger pattern with many capture groups.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29965>
_______________________________________


More information about the Python-bugs-list mailing list