Форум сайта python.su
Доброго времени суток, уважаемые.
Подскажите пожалуйста как выводить русские символы взятые из словарей?
Пример:
#!/usr/bin/python #coding=utf8 print "Русский текст" dict = {"one":"один","two":"два"} print dict
./test_dict.py Русский текст {'two': '\xd0\xb4\xd0\xb2\xd0\xb0', 'one': '\xd0\xbe\xd0\xb4\xd0\xb8\xd0\xbd'}
Офлайн
В 2.Х
dict_ = {1:u"Один", 2: u"Два"} print repr(dict_).decode("unicode_escape")
Офлайн
Ругается
print repr(dict_).decode("unicode_escape") UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-9: ordinal not in range(128)
Офлайн
Вы мой словарь или свой подставляли?
Офлайн
Ваш
Офлайн
А так можно?
#coding=utf8
#coding: utf-8
# -*- coding: utf-8 -*-
Офлайн
4kpt
#coding: utf-8
Офлайн
Еще похожий вопрос образовался, не буду создавать новую тему.
Как вывести русский текст прочитанный из файла? Вот код:
#!/usr/bin/python # coding: utf-8 inputfile = open("input.txt", "rt") for l in inputfile.readline(): print l, inputfile.close()
Привет, ребята! Как бодрость духа?
� � � � � � � � � � � � � , � � � � � � � � � � � ! � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � ?
Офлайн
#!/usr/bin/env python # -*- coding: utf-8 -*- import codecs with codecs.open('input.txt', 'r', 'utf-8') as file: for l in file: print l
Офлайн
with open('input.txt', 'r') as file: for l in file: print l
Отредактировано malya (Сен. 16, 2013 16:41:53)
Офлайн