Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一个默认编码 -如何在 Python3 中默认'cp1251'更改为?UTF-8因为函数 sys.setdefaultencoding() 不起作用
'cp1251'
UTF-8
Python3str在 unicode 中不存在。如果您正在使用 bytearray 那么
str
mystring = b'my cp1251 byte array'.decode('cp1251')
您可以将其保留为 astr或将其放入 utf-8 字节数组:
my_utf_8_bytearray = mystring.encode()