Trouble saving unicode text to file

John Machin sjmachin at lexicon.net
Sun May 8 06:35:47 EDT 2005


On Sun, 08 May 2005 11:23:49 +0200, "Martin v. Löwis"
<martin at v.loewis.de> wrote:

>Svennglenn wrote:
>> # -*- coding: cp1252 -*-
>> 
>> titel = "åäö"
>> titel = unicode(titel)
>
>Instead of this, just write
>
># -*- coding: cp1252 -*-
>
>titel = u"åäö"
>
>> fil = open("testfil.txt", "w")
>> fil.write(titel)
>> fil.close()
>
>Instead of this, write
>
>import codecs
>fil = codecs.open("testfil.txt", "w", "cp1252")
>fil.write(titel)
>fil.close()
>
>Instead of cp1252, consider using ISO-8859-1.

Martin, I can't guess the reason for this last suggestion; why should
a Windows system use iso-8859-1 instead of cp1252?

Regards,
John





More information about the Python-list mailing list