【发布时间】:2013-05-20 19:53:51
【问题描述】:
只是发布这个,以便我以后可以搜索它,因为它似乎总是难住我:
$ 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'"
作为问题:如何在 Python 3 中打印二进制 (bytes) 字符串,不带 b' 前缀?
【问题讨论】:
标签: python string python-3.x