saving cyrillic text files

Boudewijn Rempt boud at valdyas.org
Fri Aug 23 09:56:52 CEST 2002


DR wrote:

> file=open("rustext.txt", "w")
> file.write("??????")
> file.close
> 
> When I open the file with a text editor I get garbled text. I use
> russian win98 so I don't see why this shouldn't work.

Probably because Python hard-codedly assumes you want ASCII and
nothing but ASCII. Try something like:

import codecs

f = codecs.open("rustext.txt","w","iso8859_5")
f.write(u"абвгдежзий".decode("iso8859-5"))

-- 
Boudewijn Rempt | http://www.valdyas.org



More information about the Python-list mailing list