Re: string u'hyv\xe4' to file as 'hyvä'
gintare
g.statkute at gmail.com
Mon Dec 27 00:57:30 EST 2010
Hello,
STILL do not work. WHAT to be done.
import codecs
item=u'hyv\xe4'
F=codecs.open('/opt/finnish.txt', 'w+', 'utf8')
F.writelines(item.encode('utf8'))
F.close()
In file i find 'hyv\xe4' instead of hyvä.
(Sorry for mistyping in previous letter about 'latin-1'. I was making
all possible combinations, when normal example syntax did not work,
before writting to this forum.)
regards,
gintare
On 27 Gruo, 00:43, gintare <g.statk... at gmail.com> wrote:
> 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