2017-01-16 3 views
-1
a_string = 'à'.encode ('utf-8') 
print (a_string) 

b_string = '₩'.encode ('utf-8') 
print (b_string) 

a_bytes = a_string.decode ('utf-8') 
print (a_bytes) 

b_bytes = b_string.decode ('utf-8') # This line gives error: Character maps to undefined 
print (b_bytes) 

Ausgang ist:Python 3.5 kann das koreanische Won (Währung) Symbol nicht dekodieren?

enter image description here

Bin ich etwas falsch zu machen oder ist das ein Python 3.5 Problem?

Ausgabe:

import locale 

print (locale.getdefaultlocale()) 

ist:

('en_US', 'cp1252') 

Python Version 3.5.1

[EDIT]

Windows locale Problem Diese in der Tat stellt sich heraus, ist zu sein . Alles funktioniert gut unter Linux.

+0

Adaequat cmd ändern (Python 3.5.2, ubuntu 16.10): https: // i.imgur.com/raQq0JP.png – falsetru

+1

Ich habe Ihr Skript ohne Probleme auf Python 3.5.2 ausgeführt, was ist Ihre Version? – hansaplast

+1

können Sie die Ausgabe von 'locale' in Ihre Frage eingeben? – hansaplast

Antwort

1

Ihr Terminal ist auf die Codierung cp1252 eingestellt. Die Symbole à und sind nicht die unterstützten Zeichen.

Setzen Sie Ihre Shell auf z. utf-8 wie folgt aus:

export LC_ALL=UTF-8 

bearbeiten Da Sie Windows sehen this answer wie die Codierung in Windows

+0

OP kann Windows verwenden, die meistens 'CP1250' verwenden, aber nicht' export' und 'LC_ALL' haben – furas

+0

Ich bin tatsächlich auf Windows, irgendeine Lösung dafür? (außer zu Linux wechseln). –

+0

@JacquesdeHooge versuchen [change-default-code-seite-von-windows-konsole-zu-utf-8] (http://superuser.com/questions/269818/change-default-code-page-of-windows- console-to-utf-8) – furas

Verwandte Themen