how to write unicode to a txt file?
Facundo Batista
facundo at taniquetil.com.ar
Wed Jan 17 11:57:33 EST 2007
Frank Potter wrote:
> But it seems that python can't directly write unicode to a file,
You need to use the method open from module codecs:
>>> import codecs
>>> a = codecs.open("pru_uni.txt", "w", "utf-8")
>>> txt = unicode("campeĆ³n\n", "utf-8")
>>> a.write(txt)
>>> a.close()
>>>
So, then, from command line:
facundo at expiron:~$ file pru_uni.txt
pru_uni.txt: UTF-8 Unicode text
:)
Regards,
--
. Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
More information about the Python-list
mailing list