[Python-ideas] A possible transition plan to bytes-based iteration and indexing for binary data
Antoine Pitrou
antoine at python.org
Sun Jun 15 15:08:31 CEST 2014
Le 15/06/2014 08:33, Nick Coghlan a écrit :
>
> The general principle involved would be to return an integer *subtype*
> from indexing and iteration operations on bytes, bytearray and
> memoryview objects using the "default" format character. That subtype
> would then be detected in various locations and handled the way a
> length 1 bytes object would be handled, rather than the way an integer
> would be handled. The current proof of concept adds such handling to
> ord(), bytes() and bytearray() (with appropriate test cases in
> test_bytes) giving the following results:
>
>>>> b'hello'[0]
> 104
>>>> ord(b'hello'[0])
> 104
>>>> bytes(b'hello'[0])
> b'h'
>>>> bytearray(b'hello'[0])
> bytearray(b'h')
That sounds terribly confusing to me. I'd rather live with the current
behaviour.
Regards
Antoine.
More information about the Python-ideas
mailing list