开发者

Is it normal for python's io.BytesIO.getvalue() to return str instead of bytes?

开发者 https://www.devze.com 2023-03-15 04:33 出处:网络
Is it normal for python\'s io.BytesIO.getvalue() to return str instead of bytes? Python 2.7.1 (r271:86832, Jun 13 2011, 14:28:51)

Is it normal for python's io.BytesIO.getvalue() to return str instead of bytes?

 Python 2.7.1 (r271:86832, Jun 13 2011, 14:28:51) 
 >>> import io
 >>> a = io.Byte开发者_如何学CsIO()
 >>> a
 <_io.BytesIO object at 0x10f9453b0>
 >>> a.getvalue()
 ''
 >>> print type(a.getvalue())
 <type 'str'>
 >>> 

Should I file a bug?


No, this isn't a bug. This is normal behaviour. See this answer: the bytes type in python 2.7 and PEP-358

It basically comes down that the 2.7 bytes is just an alias for str to smoothen the transition to 3.x.


bytes doesn't exist as a separate kind of datastructure in Python 2.X so yes, it is entirely normal - str are bytestrings in Python 2 (unlike Python 3, where str are unicode strings).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号