classification
Title: file.encoding doesn't apply to file.write
Type: Stage:
Components: Unicode Versions: Python 2.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: lemburg Nosy List: donut, lemburg
Priority: normal Keywords:

Created on 2004-06-07 07:00 by donut, last changed 2007-01-13 19:26 by lemburg. This issue is now closed.

Messages (3)
msg21063 - (view) Author: Matthew Mueller (donut) Date: 2004-06-07 07:00
In python2.3 printing unicode to an appropriate terminal
actually works.  But using sys.stdout.write doesn't.

Ex:
Python 2.3.4 (#2, May 29 2004, 03:31:27) 
[GCC 3.3.3 (Debian 20040417)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> sys.stdout.encoding
'UTF-8'
>>> u=u'\u3053\u3093\u306b\u3061\u308f'
>>> print u
S“ka
>>> sys.stdout.write(u)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode
characters in position 0-4: ordinal not in range(128)


The file object docs say:
"encoding
    The encoding that this file uses. When Unicode
strings are written to
    a file, they will be converted to byte strings
using this encoding.
    ..."
Which indicates to me that it is supposed to work.
msg21064 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2004-07-23 10:23
Logged In: YES 
user_id=38388

The encoding feature is currently only implemented for
printing. We could also add it to .write() and .writelines()
... patches are welcome.
msg21065 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2007-01-13 19:26
Not sure whether this is still the case. No patches were provided, so closing the feature request.
History
Date User Action Args
2004-06-07 07:00:09donutcreate