]> granicus.if.org Git - python/commitdiff
Make StringIO its own iterator, similar to real files.
authorGuido van Rossum <guido@python.org>
Fri, 31 Jan 2003 16:04:15 +0000 (16:04 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 31 Jan 2003 16:04:15 +0000 (16:04 +0000)
(This should also be done to cStringIO.)

Lib/StringIO.py

index 79ab7e16b3291c35da4f4cecffa9c6b03fa542da..89dda5e95d118d5ab737b7da8e2da6a0baa53405 100644 (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.