Message6667

Author ssoldatenko
Recipients ssoldatenko
Date 2011-10-11.06:42:28
SpamBayes Score 2.85416e-12
Marked as misclassified No
Message-id <1318315349.14.0.275978336981.issue1807@psf.upfronthosting.co.za>
In-reply-to
Content
Failed to set UTF-8 encoding for output redirected to file.

--------x.py--------
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys

print sys.stdout.encoding
print sys.getdefaultencoding()

print(u"Ф")
--------x.py--------

=== Output to console works fine ===

$ java -jar jython.jar -Dpython.console.encoding=UTF-8 x.py
UTF-8
ascii
Ф

=== Output to file does not work ===

$ java -jar jython.jar -Dpython.console.encoding=UTF-8 x.py > tmp.txt 2>tmp2.txt ; cat tmp.txt
$ cat tmp.txt
None
ascii
$ cat tmp2.txt
Traceback (most recent call last):
  File "x.py", line 9, in <module>
    print(u"Ф")
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0424' in position 0: ordinal not in range(128)
History
Date User Action Args
2011-10-11 06:42:29ssoldatenkosetrecipients: + ssoldatenko
2011-10-11 06:42:29ssoldatenkosetmessageid: <1318315349.14.0.275978336981.issue1807@psf.upfronthosting.co.za>
2011-10-11 06:42:29ssoldatenkolinkissue1807 messages
2011-10-11 06:42:28ssoldatenkocreate