[Python-de] UTF-8 Python Datei
Simon Pamies
bipbap at gmx.de
Mon Apr 25 21:40:40 CEST 2005
Am 25.04.2005 um 20:53 schrieb Albert Hermeling:
> Am Montag, 25. April 2005 20:49 schrieb Simon Pamies:
>
> Guten Abend Simon,
>
>>> print type("Äpfel")
>>
>> print type(u"Äpfel")
>>
>>> <type 'unicode'> <------- Richtig!!
>>> <type 'str'> <------- Warum ist das ein String???
>
> Das Skript ist! unicode warum ist dann type("Äpfel") im unicode Skript
> nicht
> von type unicode?
Das Skript (der Code) ist Unicode, aber die einzelnen Strings die du
dort benutzt (alles innerhalb von quotes) sind erstmal ascii.
Das folgende Skript funktioniert:
#!/usr/bin/python
#-*- coding: UTF-8 -*-
import codecs
f = codecs.open("test.txt","rb","utf8").read()
print type(f)
print type(u"Äpfel")
if f == u"Äpfel":
print "Das ist Richtig"
-S