Код: Выделить всё
with open(file, 'r', encoding="cp1252") as file_with_strings:
# save some strings
Код: Выделить всё
print(some_string)
# => UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 180: ordinal not in range(128)
print(some_string.decode("utf-8"))
# => AttributeError: 'str' object has no attribute 'decode'
sys.stdout.buffer.write(some_str)
# => TypeError: 'str' does not support the buffer interface
print(some_string.encode("cp1252").decode("utf-8"))
# => UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 180: invalid continuation byte
print(some_string.encode("cp1252"))
# => has the unfortunate result of printing b'' instead of just the string
Хотелось бы некоторых разъяснений ! Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/357 ... n-python-3