470,811 Members | 1,101 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

how to control file output encoding?

the encoding of file that is output by the file.write() function is
always None.
and the encoding attribute of the File Object is readonly.

f = open('abc.txt','w')
print f.encoding
>>None
how can I change the file output encoding?

Sep 20 '06 #1
1 2215
In <ma**************************************@python.o rg>, MaTianyi wrote:
the encoding of file that is output by the file.write() function is
always None.
and the encoding attribute of the File Object is readonly.

f = open('abc.txt','w')
print f.encoding
>>>None

how can I change the file output encoding?
Use the `open()` function in the `codecs` module:

import codecs
f = codecs.open('abc.txt', 'w', 'utf-8')

Ciao,
Marc 'BlackJack' Rintsch
Sep 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Koulbak | last post: by
4 posts views Thread by Carlo Marchesoni | last post: by
11 posts views Thread by scorpion53061 | last post: by
12 posts views Thread by Adam J. Schaff | last post: by
12 posts views Thread by Brian Henry | last post: by
1 post views Thread by MaTianyi | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.