homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author max-alleged
Recipients max-alleged
Date 2011年05月24日.19:49:09
SpamBayes Score 3.5937148e-06
Marked as misclassified No
Message-id <1306266550.46.0.554812052221.issue12170@psf.upfronthosting.co.za>
In-reply-to
Content
Bytes objects when indexed provide integers, but do not accept them to many functions, making them inconsistent with other sequences.
Basic example:
>>> test = b'012'
>>> n = test[1]
>>> n
49
>>> n in test
True
>>> test.index(n)
TypeError: expected an object with the buffer interface.
It is certainly unusual for n to be in the sequence, but not to be able to find it. I would expect the result to be 1. This set of commands with list, strings, tuples, but not bytes objects.
I suspect, from issue #10616, that all the following functions would be affected:
"bytes methods: partition, rpartition, find, index, rfind, rindex, count, translate, replace, startswith, endswith"
It would make more sense to me that instead of only supporting buffer interface objects, they also accept a single integer, and treat it as if it were provided a length-1 bytes object.
The use case I came across this problem was something like this:
Given seq1 and seq2, sequences of the same type:
[seq1.index(x) for x in seq2]
This works for strings, lists, tuples, but not bytes.
History
Date User Action Args
2011年05月24日 19:49:10max-allegedsetrecipients: + max-alleged
2011年05月24日 19:49:10max-allegedsetmessageid: <1306266550.46.0.554812052221.issue12170@psf.upfronthosting.co.za>
2011年05月24日 19:49:09max-allegedlinkissue12170 messages
2011年05月24日 19:49:09max-allegedcreate

AltStyle によって変換されたページ (->オリジナル) /