Oleg Broytmann wrote:
> On Wed, Apr 16, 2008 at 10:11:13PM +1000, Nick Coghlan wrote:
>> atsuo ishimoto wrote:
>>> IOError: [Errno 2] No such file or directory: '\u65e5\u672c\u8a9e'
>> This is starting to seem to me more like something to be addressed
>> through sys.displayhook/excepthook at the interactive interpreter level
>
> The problem manifests itself in scripts, too:
>
> Traceback (most recent call last):
> File "./ttt.py", line 4, in <module>
> open("тест") # filename is in koi8-r encoding
> IOError: [Errno 2] No such file or directory: '\xd4\xc5\xd3\xd4'
Hmm, the io module along with sys.stdout/err may be a better way to
attack the problem then. Given:
import sys, io
class ParseUnicodeEscapes(io.TextIOWrapper):
def write(self, text):
super().write(text.encode('latin-1').decode('unicode_escape'))
args = (sys.stdout.buffer, sys.stdout.encoding, sys.stdout.errors,
None, sys.stdout.line_buffering)
sys.stdout = ParseUnicodeEscapes(*args)
args = (sys.stderr.buffer, sys.stderr.encoding, sys.stderr.errors,
None, sys.stderr.line_buffering)
sys.stderr = ParseUnicodeEscapes(*args)
You get:
>>> "тест"
'тест'
>>> open("тест")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ncoghlan/devel/py3k/Lib/io.py", line 212, in __new__
return open(*args, **kwargs)
File "/home/ncoghlan/devel/py3k/Lib/io.py", line 151, in open
closefd)
IOError: [Errno 2] No such file or directory: 'тест'
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com