Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1265bd

Browse files
committed
Make StringIO its own iterator, similar to real files.
(This should also be done to cStringIO.)
1 parent 5b8132f commit c1265bd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/StringIO.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ def __init__(self, buf = ''):
5959
self.softspace = 0
6060

6161
def __iter__(self):
62-
return iter(self.readline, '')
62+
return self
63+
64+
def next(self):
65+
if self.closed:
66+
raise StopIteration
67+
r = self.readline()
68+
if not r:
69+
raise StopIteration
70+
return r
6371

6472
def close(self):
6573
"""Free the memory buffer.

0 commit comments

Comments
 (0)