string u'hyv\xe4' to file as 'hyvä'

gintare g.statkute at gmail.com
Sun Dec 26 17:43:03 EST 2010


Could you please help me with special characters saving to file.

I need to write the string u'hyv\xe4' to file.
I would like to open file and to have line 'hyvä'

import codecs
word= u'hyv\xe4'
F=codecs.open(/opt/finnish.txt, 'w+','Latin-1')

F.writelines(item.encode('Latin-1'))
F.writelines(item.encode('utf8'))
F.writelines(item)

F.close()

All three writelines gives the same result in finnish.txt:   hyv\xe4
i would like to find 'hyvä'.

regards,
gintare



More information about the Python-list mailing list