AttributeError: <unprintable AttributeError object> <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode characters in position 29-37: ordinal not in range(128)
>> str(u'\u0100') Traceback (most recent call last): File "<interactive input>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\u0100' in position 0: ordinal not in range(128)
>>> str(u'\u0100'.encode('utf-8')) '\xc4\x80'
# unicode.py This Python file uses the following encoding: utf-8 import encodings.utf_8_sig comment = """ <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> To make your pages display properly in Unicode, you need to change this to: <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> import codecs f = codecs.open("file","w",encoding='utf-8') f.write(stuff) f.close() """ ##Ā = A- ##Ē = E- ##Ī = I- ##Ō = O- ##Ū = U- ##ā = a- ##ē = e- ##ī = i- ##ō = o- ##ū = u- dMacron = { "A" : u'\u0100', "a" : u'\u0101', "E" : u'\u0112', "e" : u'\u0113', "I" : u'\u012A', "i" : u'\u012B', "O" : u'\u014C', "o" : u'\u014D', "U" : u'\u016A', "u" : u'\u016B' } f1 = open("e:/project/training/unicode/unicode_sample.txt","w") print # read-only f1.encoding # = "utf8" # print >> f1,dMacron # cannot do this to ascii encoder mO = u"\N{LATIN CAPITAL LETTER O WITH MACRON}" word = "Maori".replace("o",dMacron["o"]) print >> f1,word.encode('utf-8') # PyUnicode.__print__ word.encode('utf-8') lstKey = dMacron.keys() lstKey.sort() for k in lstKey : print >> f1,dMacron.encode('utf-8'), print dMacron, ##mA = u'\u0100' ##ma = u'\u0101' ##mE = u'\u0112' ##me = u'\u0113' ##mI = u'\u012A' ##mi = u'\u012B' ##mO = u'\u014C' ##mo = u'\u014D' ##mU = u'\u016A' ##mu = u'\u016B' # word = "Maori".replace("o",dMacron["o"]) mO = u"\N{LATIN CAPITAL LETTER O WITH MACRON}" word = "MAORI".replace("O",mO) print >> f1,word.encode('utf-8') print word f1.close() print "success"
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.