Message104375
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')
16
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')
16
>>> 'scientific american'.rfind('c', 15)
16
>>> 'scientific american'.rfind('c', 14)
16
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. |
|
Date |
User |
Action |
Args |
2010-04-27 22:20:22 | dtorp | set | recipients:
+ dtorp |
2010-04-27 22:20:21 | dtorp | set | messageid: <1272406821.86.0.455746879552.issue8551@psf.upfronthosting.co.za> |
2010-04-27 22:20:20 | dtorp | link | issue8551 messages |
2010-04-27 22:20:19 | dtorp | create | |
|