summaryrefslogtreecommitdiffstats
path: root/Lib/StringIO.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-01-31 16:04:15 (GMT)
committerGuido van Rossum <guido@python.org>2003-01-31 16:04:15 (GMT)
commitc1265bd9a65b510c290667f7d9fbbf6e3156f386 (patch)
tree28d9bb11271986a8ff056213b0774e34d9a29875 /Lib/StringIO.py
parent5b8132ffa34244cc24b603d8462e6e733e014e71 (diff)
downloadcpython-c1265bd9a65b510c290667f7d9fbbf6e3156f386.zip
cpython-c1265bd9a65b510c290667f7d9fbbf6e3156f386.tar.gz
cpython-c1265bd9a65b510c290667f7d9fbbf6e3156f386.tar.bz2
Make StringIO its own iterator, similar to real files.
(This should also be done to cStringIO.)
Diffstat (limited to 'Lib/StringIO.py')
-rw-r--r--Lib/StringIO.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index 79ab7e1..89dda5e 100644
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -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.