Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 7, 2015 09:43
Show Gist options
  • Save poros/5c38a443a5fb00d7ae28 to your computer and use it in GitHub Desktop.
Save poros/5c38a443a5fb00d7ae28 to your computer and use it in GitHub Desktop.
Generator storing the last value returned
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