Created
October 7, 2015 09:43
-
-
Save poros/5c38a443a5fb00d7ae28 to your computer and use it in GitHub Desktop.
Generator storing the last value returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class storelast(object): | |
def __init__(self,source): | |
self.source = source | |
def next(self): | |
item = self.source.next() | |
self.last = item | |
return item | |
def __iter__(self): | |
return self | |
lines = storelast(for line in open("run/foo/access-log")) | |
for line in lines: | |
print line | |
print lines.last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment