Unicode in writing to a file

Marco Mariani marco at sferacarta.com
Thu Apr 23 14:18:20 CEST 2009


Carbon Man wrote:

> Py 2.5
> Trying to write a string to a file.
> self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue)
> cValue contains a unicode character. node.tagName is also a unicode string 
> though it has no special characters in it.

So what's the encoding of your file?

If you didn't open dataUpdate with codecs.open, and you don't encode the 
string someway - i.e. text.encode('utf-8') python has no way to know it.




More information about the Python-list mailing list