Make StringIO its own iterator, similar to real files.

(This should also be done to cStringIO.)
This commit is contained in:
Guido van Rossum 2003-01-31 16:04:15 +00:00
parent 5b8132ffa3
commit c1265bd9a6
1 changed files with 9 additions and 1 deletions

View File

@ -59,7 +59,15 @@ class StringIO:
self.softspace = 0
def __iter__(self):
return iter(self.readline, '')
return self
def next(self):
if self.closed:
raise StopIteration
r = self.readline()
if not r:
raise StopIteration
return r
def close(self):
"""Free the memory buffer.