[Python-Dev] isatty() on closed StringIO (was: Iterating a closed StringIO)

Walter Dörwald walter at livinglogic.de
Fri Nov 18 13:15:33 CET 2005


Guido van Rossum wrote:

> On 11/17/05, Walter Dörwald <walter at livinglogic.de> wrote:
> 
>>Am 17.11.2005 um 22:03 schrieb Guido van Rossum:
>>
>>
>>>On 11/17/05, Walter Dörwald <walter at livinglogic.de> wrote:
>>>
>>>>Currently StringIO.StringIO and cStringIO.StringIO behave differently
>>>>when iterating a closed stream:
 > [...]
> 
> I hope there isn't anyone here who believes this patch would be a bad idea?

BTW, isatty() has a similar problem:

 >>> import StringIO, cStringIO
 >>> s = StringIO.StringIO()
 >>> s.close()
 >>> s.isatty()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/usr/local/lib/python2.4/StringIO.py", line 93, in isatty
     _complain_ifclosed(self.closed)
   File "/usr/local/lib/python2.4/StringIO.py", line 40, in 
_complain_ifclosed
     raise ValueError, "I/O operation on closed file"
ValueError: I/O operation on closed file
 >>> s = cStringIO.StringIO()
 >>> s.close()
 >>> s.isatty()
False

I guess cStringIO.StringIO.isatty() should raise an exception too.

Bye,
    Walter Dörwald


More information about the Python-Dev mailing list