Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9322

Re: How to write a file generator

Date 2011-07-12 17:52 +0200
From Thomas Jollans <t@jollybox.de>
Subject Re: How to write a file generator
References <ivhmoc$6t3$1@speranza.aioe.org>
Newsgroups comp.lang.python
Message-ID <mailman.944.1310485982.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 07/12/2011 04:46 PM, Billy Mays wrote:
> 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

http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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