[New-bugs-announce] [issue21363] io.TextIOWrapper always closes wrapped files

Armin Ronacher report at bugs.python.org
Sun Apr 27 14:56:29 CEST 2014


New submission from Armin Ronacher:

I'm trying to write some code that fixes a misconfigured sys.stdin on a case by case bases but unfortunately I cannot use TextIOWrapper for this because it always closes the underlying file:


Python

>>> import io
>>> sys.stdin.encoding
'ANSI_X3.4-1968'
>>> stdin = sys.stdin
>>> correct_stdin = io.TextIOWrapper(stdin.buffer, 'utf-8')
>>> correct_stdin.readline()
foobar
'foobar\n'
>>> del correct_stdin
>>> stdin.readline()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.

Ideally there would be a way to disable this behavior.

----------
messages: 217260
nosy: aronacher
priority: normal
severity: normal
status: open
title: io.TextIOWrapper always closes wrapped files

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21363>
_______________________________________


More information about the New-bugs-announce mailing list