Message226896
| Author |
martin.panter |
| Recipients |
Arfrever, elixir, ishimoto, jwilk, loewis, martin.panter, methane, mrabarnett, ncoghlan, nikratio, pitrou, rurpy2, serhiy.storchaka, vstinner |
| Date |
2014年09月15日.04:36:48 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1410755809.04.0.13730713043.issue15216@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Some more use cases for temporarily switching error handler in the middle of writing to a stream:
* Possibly simplify the implementation of sys.displayhook()
* I have done a similar hack at <https://bitbucket.org/Gfy/pyrescene/commits/42ad75e375d84e090a32d024acc865de341c22aa#Lrescene/srr.pyF132>, to output a comment field with a permissive error handler, while other data is output with strict error handling.
A use case for changing a reader’s newline translation mode is to use standard input with the built-in "csv" module. My current idea is to do something like this:
encoding = sys.stdin.encoding
errors = sys.stdin.errors
line_buffering = sys.stdin.line_buffering
# No way to retain write_through mode, but shouldn’t matter for reading
sys.stdin = TextIOWrapper(sys.stdin.detach(), encoding, errors,
newline="", line_buffering=line_buffering)
for row in csv.reader(sys.stdin):
...
On the other hand, I wonder about rewinding an input file after already having read and buffered text in the wrong encoding. From a distance, the Python native version of the code seems rather complex and full of dark magic. Is there a use case, or maybe it would be simpler to have it only work when nothing has been read or buffered? |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2014年09月15日 04:36:49 | martin.panter | set | recipients:
+ martin.panter, loewis, ishimoto, ncoghlan, pitrou, vstinner, jwilk, mrabarnett, Arfrever, methane, nikratio, rurpy2, serhiy.storchaka, elixir |
| 2014年09月15日 04:36:49 | martin.panter | set | messageid: <1410755809.04.0.13730713043.issue15216@psf.upfronthosting.co.za> |
| 2014年09月15日 04:36:49 | martin.panter | link | issue15216 messages |
| 2014年09月15日 04:36:48 | martin.panter | create |
|