Добрый вечер буду крайне признателен если кто объяснит как выбрать кодировку например
#1251 откуда она берется зависит ли от версии как её поменять
какие для кирилицы… зачем нужны кодировки..
s = "Привет" new_s = s.encode("windows-1251") type(new_s)#builtins.bytes
s = b'\xcf\xf0\xe8\xe2\xe5\xf2' new_s = s.decode("windows-1251") print(new_s)
#Python 2 import io with io.open("C:\\Users\\myfile.txt", "r", encoding="windows-1251") as myfile: print myfile.read()
#Python 3 with open("C:\\Users\\myfile.txt", "r", encoding="windows-1251") as myfile: print(myfile.read())
vaxхорошая попытка, но не совсем удачная.
Попробую ответить:
The items of a Unicode object are Unicode code units. A Unicode code unit is represented by a Unicode object of one item and can hold either a 16-bit or 32-bit value representing a Unicode ordinal (the maximum value for the ordinal is given in sys.maxunicode, and depends on how Python is configured at compile time)А это очень важно. Тем более нужно понимать отличия объекта Unicode и текста кодированным по стандарту Юникод.
# -*- coding: utf-8 -*-