[Python-Dev] Python 3.x and bytes (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed May 18 21:29:47 CEST 2011
- Previous message: [Python-Dev] Python 3.x and bytes
- Next message: [Python-Dev] Python 3.x and bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ethan Furman wrote:
Greg Ewing wrote:
As for
--> someothervar[3] == b'd' there ought to be a literal for specifying an integer using an ascii character, so you could say something like if someothervar[3] == c'd': which would be equivalent to if someothervar[3] == ord(b'd') but without the overhead of computing the value each time at run time. Given that we can't change the behavior of b'abc'[1], that would be better than what we have. +1
Here's another thought, that perhaps is not backwards-incompatible...
some_var[3] == b'd'
At some point, the bytes class' eq will be called -- is there a reason why we cannot have
- a check to see if the bytes instance is length 1
- a check to see if
i) the other object is an int, and
- 0 <= other_obj < 256
- if 1 and 2, make the comparison instead of returning NotImplemented?
This makes sense to me -- after all, the bytes class is an array of ints in range(256); it is a special case, but doesn't feel any more special than passing an int into bytes() giving a string of that many null bytes; and it would get rid of the, in my opinion ugly, idiom of
some_var[i:i+1] == b'd'
It would also not require a new literal syntax.
Ethan
- Previous message: [Python-Dev] Python 3.x and bytes
- Next message: [Python-Dev] Python 3.x and bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]