diff options
| author | Guido van Rossum <guido@python.org> | 2003-01-31 16:04:15 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2003-01-31 16:04:15 +0000 |
| commit | c1265bd9a65b510c290667f7d9fbbf6e3156f386 (patch) | |
| tree | 28d9bb11271986a8ff056213b0774e34d9a29875 /Lib/StringIO.py | |
| parent | 5b8132ffa34244cc24b603d8462e6e733e014e71 (diff) | |
| download | cpython-git-c1265bd9a65b510c290667f7d9fbbf6e3156f386.tar.gz | |
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.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 79ab7e16b3..89dda5e95d 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. |
