python的io.BytesIO.getvalue()
返回str而不是字节是否正常?
Python 2.7.1 (r271:86832, Jun 13 2011, 14:28:51)
>>> import io
>>> a = io.BytesIO()
>>> a
<_io.BytesIO object at 0x10f9453b0>
>>> a.getvalue()
''
>>> print type(a.getvalue())
<type 'str'>
>>>
我应该提出一个错误吗?
Tags:
不,你不应该提出一个错误。这是正常的行为。看这个答案:the bytes type in python 2.7 and PEP-358
基本上,2.7
bytes
只是str
平滑过渡到3.x的别名bytes
在Python 2.X中不作为一种独立的数据结构存在,所以是的,这是完全正常的-str
是python2中的bytestrings(不像Python 3中的str
是unicode字符串)。相关问题 更多 >
编程相关推荐