Chỉ cần đăng này vì vậy tôi có thể tìm kiếm nó sau này, vì nó luôn luôn có vẻ Stump tôi:Suppress/in mà không b' tiền tố cho byte trong Python 3
$ python3.2
Python 3.2 (r32:88445, Oct 20 2012, 14:09:50)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> print(curses.version)
b'2.2'
>>> print(str(curses.version))
b'2.2'
>>> print(curses.version.encode('utf-8'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'bytes' object has no attribute 'encode'
>>> print(str(curses.version).encode('utf-8'))
b"b'2.2'"
Như câu hỏi: làm thế nào để in một nhị phân (bytes
) chuỗi trong Python 3, không có tiền tố b'
?
liên quan: [? Làm thế nào để viết byte vào một tập tin bằng Python 3 mà không biết mã hóa] (https://stackoverflow.com/q/ 4290716/4279) – jfs