2017-04-06 7 views
0
The string that could not be encoded/decoded was: 熔树脂温度(℃) 

    'ascii' codec can't encode characters in position 0-4: ordinal not in range(128) 

Ich versuche, den Ascii-Zeichen zu kodieren, aber ich bekomme Fehler. Ich habe versucht mitWie kodiere oder dekodiere ich Ascii Codec?

熔树脂温度(℃).encode('utf-8') 
熔树脂温度(℃).encode('utf8') 
unicode(熔树脂温度(℃),'utf-8') 

Nichts funktioniert.

+0

Ich glaube, Sie brauchen nicht Unicode – chbchb55

+0

'.encode ascii ('utf-8')' nicht funktioniert? Für mich geht das. – Rishav

+1

Ich bin mir nicht sicher, ob Python-2.7 Unicode hat zwar aktiviert, müssen Sie wahrscheinlich python3 – chbchb55

Antwort

0

Um in Unicode zu umwandeln:

In [1]: str1 = '熔树脂温度(℃)' 

In [2]: print str1 
熔树脂温度(℃) 

In [3]: str1 
Out[3]: '\xe7\x86\x94\xe6\xa0\x91\xe8\x84\x82\xe6\xb8\xa9\xe5\xba\xa6(\xe2\x84\x83)' 

In [4]: unicode_str1 = str1.decode('UTF-8') 

In [5]: print unicode_str1 
熔树脂温度(℃) 

In [6]: unicode_str1 
Out[6]: u'\u7194\u6811\u8102\u6e29\u5ea6(\u2103)' 
+0

Dies setzt voraus, dass OP eine Python-Shell ausführt, die utf-8 verwendet. Angenommen, das war eine Windows-Codepage? – tdelaney

Verwandte Themen