Message147010
| Author |
pitrou |
| Recipients |
benjamin.peterson, ezio.melotti, pitrou, stefanholek |
| Date |
2011年11月04日.15:06:18 |
| SpamBayes Score |
1.6653345e-16 |
| Marked as misclassified |
No |
| Message-id |
<1320419180.24.0.212801305164.issue13342@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> There cannot be a reason input() should be confined to "strict", or can
> there? ;-)
Actually, there's a good reason: in the non-interactive case, input() simply calls sys.stdin.read(), which doesn't have encoding or errors attributes. You want to override sys.stdin so that it has the right error handler.
However, there is a bug in input() in that it ignores sys.stdin's error handler in interactive mode (where it delegates to the readline library, if present):
>>> import sys, io
>>> sys.stdin = io.TextIOWrapper(sys.stdin.detach(), "ascii", "replace")
>>> sys.stdin.read()
héhé
'h��h��\n'
>>> input()
héhé
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
If you don't mind losing GNU readline functionality, the immediate workaround for you is to use sys.stdin.read() directly. |
|