Keithx
Keithx

Reputation: 3158

Changing encoding python 3

Have a default encoding of 'cp1251'-how can it be changed to UTF-8 by default in Python3? Because the function sys.setdefaultencoding() is not working

Upvotes: 0

Views: 1910

Answers (1)

Muposat
Muposat

Reputation: 1506

Python3's str is aways in unicode. If you are working with bytearray then

mystring = b'my cp1251 byte array'.decode('cp1251')

You can keep it as a str or put it into utf-8 byte array:

my_utf_8_bytearray =  mystring.encode()

Upvotes: 1

Related Questions