From c1265bd9a65b510c290667f7d9fbbf6e3156f386 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 31 Jan 2003 16:04:15 +0000 Subject: [PATCH] Make StringIO its own iterator, similar to real files. (This should also be done to cStringIO.) --- Lib/StringIO.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 79ab7e16b32..89dda5e95d1 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.