Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9318
| From | Billy Mays <noway@nohow.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | How to write a file generator |
| Date | 2011-07-12 10:46 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ivhmoc$6t3$1@speranza.aioe.org> (permalink) |
I want to make a generator that will return lines from the tail of
/var/log/syslog if there are any, but my function is reopening the file
each call:
def getLines():
with open('/var/log/syslog', 'rb') as f:
while True:
line = f.readline()
if line:
yield line
else:
raise StopIteration
I know the problem lies with the StopIteration, but I'm not sure how to
tell the caller that there are no more lines for now.
--
Bill
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How to write a file generator Billy Mays <noway@nohow.com> - 2011-07-12 10:46 -0400
Re: How to write a file generator "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-07-12 08:34 -0700
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 17:52 +0200
Re: How to write a file generator Billy Mays <noway@nohow.com> - 2011-07-12 12:42 -0400
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 21:04 +0200
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 21:05 +0200
Re: How to write a file generator sturlamolden <sturlamolden@yahoo.no> - 2011-07-12 09:53 -0700
Re: How to write a file generator Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-07-13 01:26 +0200
csiph-web