Unicode output to file
Евгений Косенко
eugine_kosenko at ukr.net
Sun Nov 30 18:29:21 EST 2003
Hi!
The next program
f = file("content.new", "wb")
print f.encoding
f.write(u"Привет")
Gives the next results:
sys:1: DeprecationWarning: Non-ASCII character '\xcf' in file xp.py on line
10, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details
None
Traceback (most recent call last):
File "xp.py", line 10, in ?
f.write(u"Привет")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5:
ordinal not in range(128)
I use here Russian letters, and need special encoding for them. The property
'encoding' is read-only, and is None by default. How to cast the encoding for
a file?
More information about the Python-list
mailing list