Я не могу правильно кодировать и декодировать строку, содержащую одинарные и двойные кавычки. Примечание. Мне нужно показать кавычки.Кодировать/декодировать строку с кавычками
Я сохранил следующую строку в txt-файле.
Here’s their mantra: “Eat less and exercise more. The secret to weight loss is energy balance. There are no good or bad calories. It’s all about moderation.”
with open ("file.txt", "r") as myfile:
data = myfile.read()
myfile.close()
print data
the result:

HereΓÇÖs their mantra: ΓÇ£Eat less and exercise more. The secret to weight loss is energy balance. There are no good or bad calories. ItΓÇÖs all about moderation.ΓÇ¥
я могу полностью опустить кавычки, но мне нужно, чтобы показать им
print data.decode('ascii', 'ignore')
Heres their mantra: Eat less and exercise more. The secret to weight loss is energy balance. There are no good or bad calories. Its all about moderation.
print json.dumps(data)
"\ufeff\nHere\u2019s their mantra: \u201cEat less and exercise more. The secret to weight loss is energy balance. There are no good or bad calories. It\u2019s all about moderation.\u201d "
Консоль или терминальное кодирование не поддерживает UTF-8 (кодирование вашего входного файла). Вместо этого консоль использует cp437. –
Итак, что мне делать? –
Что вы * стараетесь делать? Ваша консольная кодировка не поддерживает «причудливые» цитаты в тексте; вы можете заменить их эквивалентами ASCII или изменить кодировку консоли. –