mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
Make StringIO its own iterator, similar to real files.
(This should also be done to cStringIO.)
This commit is contained in:
parent
5b8132ffa3
commit
c1265bd9a6
1 changed files with 9 additions and 1 deletions
|
|
@ -59,7 +59,15 @@ def __init__(self, buf = ''):
|
||||||
self.softspace = 0
|
self.softspace = 0
|
||||||
|
|
||||||
def __iter__(self):
|
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):
|
def close(self):
|
||||||
"""Free the memory buffer.
|
"""Free the memory buffer.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue