在Python 3中禁止/打印不带b'前缀的字节
只需发布此内容,以便稍后查找,因为它总是让我感到困惑: $ 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 …