Message136878
> It is certainly unusual for n to be in the sequence, but not to be able to find it.
Agreed. Doc Lib: 4.6. Sequence Types — str, bytes, bytearray, list, tuple, range says '''
s.index(i) index of the first occurence of i in s
s.count(i) total number of occurences of i in s '''
so everything *in* a bytes should be valid for .index and .count.
>>> test = b'0120'
>>> z = b'0'
>>> zo = ord(z)
>>> z in test
True
>>> zo in test
True
>>> test.index(z)
0
>>> test.index(zo)
...
TypeError: expected an object with the buffer interface
>>> test.count(z)
2
>>> test.count(zo)
...
TypeError: expected an object with the buffer interface
# longer subsequences like b'01' also work
So I think the code for 3.2+ bytes.count() and bytes.index() should do the same branching as the code for bytes.__contains__.
The other functions you list, including .rindex are not general sequence functions but are string functions defined as taking subsequences as inputs. So they would never be used in generic code like .count and .index can be. |
|
Date |
User |
Action |
Args |
2011-05-25 17:41:16 | terry.reedy | set | recipients:
+ terry.reedy, max-alleged, petri.lehtinen |
2011-05-25 17:41:16 | terry.reedy | set | messageid: <1306345276.32.0.812617899215.issue12170@psf.upfronthosting.co.za> |
2011-05-25 17:41:15 | terry.reedy | link | issue12170 messages |
2011-05-25 17:41:15 | terry.reedy | create | |
|