[issue8551] Start argument for str.rfind used incorrectly
David Albert Torpey
report at bugs.python.org
Wed Apr 28 00:20:22 CEST 2010
New submission from David Albert Torpey <dtorp at users.sourceforge.net>:
The purpose of the start argument in str.find() and str.rfind() is to allow for repeated searches.
>>> def find_third_occurrence(s, value):
... p = s.find(value)
... p = s.find(value, p+1)
... return s.find(value, p+1)
>>> find_third_occurrence('scientific american', 'c')
The rfind() method is meant for searching from the right, but its start argument is used internally as if it were searching from the left. This bug makes it useless for repeated searches from the right.
>>> 'scientific american'.rfind('c')
>>> 'scientific american'.rfind('c', 15)
>>> 'scientific american'.rfind('c', 14)
Having found the first 'c' from the right at position 16, there is no way to tell it to search further from the right and find the second 'c' at position 9.
components: Interpreter Core
title: Start argument for str.rfind used incorrectly
versions: Python 2.6, Python 3.1
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list