Am 12.07.2011 16:46 schrieb Billy Mays:
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
...
I have another solution: an object which is not an iterator, but an
iterable.
class Follower(objec
On 07/12/2011 06:42 PM, Billy Mays wrote:
> On 07/12/2011 11:52 AM, Thomas Jollans wrote:
>> 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:
>>
On 07/12/2011 06:42 PM, Billy Mays wrote:
> On 07/12/2011 11:52 AM, Thomas Jollans wrote:
>> 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:
>>
On 7/12/2011 10:46 AM, 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 l
On 12 Jul, 16:46, Billy Mays wrote:
> 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.
Try 'yield None' instead of 'raise StopIteration'.
Sturla
--
http://mail.python.org/mailman/listinfo/python-list
On 07/12/2011 11:52 AM, Thomas Jollans wrote:
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') a
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:
>
On Jul 12, 4: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
Err... I must have missed something, but python files are their own
iterators.
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type
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: