[Python-Dev] bytes (original) (raw)
[Python-Dev] bytes / unicode
P.J. Eby pje at telecommunity.com
Mon Jun 21 19:29:55 CEST 2010
- Previous message: [Python-Dev] bytes / unicode
- Next message: [Python-Dev] bytes / unicode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 05:49 PM 6/21/2010 +0100, Michael Foord wrote:
Why is your proposed bstr wrapper not practical to implement outside the core and use in your own libraries and frameworks?
contains doesn't have a converse operation, so you can't code a type that works around this (Python 3.1 shown):
from os.path import join join(b'x','y') Traceback (most recent call last): File "", line 1, in File "c:\Python31\lib\ntpath.py", line 161, in join if b[:1] in seps: TypeError: Type str doesn't support the buffer API join('y',b'x') Traceback (most recent call last): File "", line 1, in File "c:\Python31\lib\ntpath.py", line 161, in join if b[:1] in seps: TypeError: 'in ' requires string as left operand, not bytes
IOW, only one of these two cases can be worked around by using a bstr (or ebytes) that doesn't have support from the core string type.
I'm not sure if the "in" operator is the only case where implementing such a type would fail, but it's the most obvious one. String formatting, of both the % and .format() varieties is another. (rmod doesn't help if your bytes object is one of several data items in a tuple or dict -- the common case for % formatting.)
- Previous message: [Python-Dev] bytes / unicode
- Next message: [Python-Dev] bytes / unicode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]