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

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

  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'> >>> 

Should I record an error?

+6
source share
2 answers

No, you should not indicate an error. This is normal behavior. See this answer: byte type in python 2.7 and PEP-358

This basically means that 2.7 bytes is just an alias for str to smooth the transition to 3.x.

+13
source

bytes does not exist as a separate kind of data structure in Python 2.X, so yes, it’s absolutely normal - str are bytes in Python 2 (unlike Python 3, where str are Unicode strings).

+1
source

Source: https://habr.com/ru/post/891354/


All Articles