Author ezio.melotti
Recipients anilbey, docs@python, ezio.melotti, mrabarnett, rhettinger, serhiy.storchaka, timehorse, tlynn
Date 2019-07-16.00:36:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563237405.05.0.879538158389.issue7940@roundup.psfhosted.org>
In-reply-to
Content
> Are there any real world examples which show the benefit of supporting 
> negative indices?

A common case is ignoring parentheses at the beginning/end, e.g.
>>> re.compile('[^,]+').findall('(foo,123,(),bar)')
['(foo', '123', '()', 'bar)']
>>> # ignore the surrounding ()
>>> re.compile('[^,]+').findall('(foo,123,(),bar)', 1, 15)
['foo', '123', '()', 'bar']
>>>
>>> # extract attributes from a tag (poc, doesn't handle all cases)
>>> re.compile('[^ ]+').findall('<input type="checkbox" id="foo" checked>', 7, 39)
['type="checkbox"', 'id="foo"', 'checked']

In both cases using -1 as endpos is simpler.
History
Date User Action Args
2019-07-16 00:36:45ezio.melottisetrecipients: + ezio.melotti, rhettinger, tlynn, timehorse, mrabarnett, docs@python, serhiy.storchaka, anilbey
2019-07-16 00:36:45ezio.melottisetmessageid: <1563237405.05.0.879538158389.issue7940@roundup.psfhosted.org>
2019-07-16 00:36:45ezio.melottilinkissue7940 messages
2019-07-16 00:36:44ezio.melotticreate