Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:bug': 0.04; 'raises': 0.07; 'bug?': 0.09; 'wrote:': 0.15; "'rb')": 0.16; 'behavior?': 0.16; 'billy': 0.16; 'expected.': 0.16; 'iterator': 0.16; 'workaround': 0.16; '\xa0for': 0.16; 'protocol': 0.16; 'subsequent': 0.16; 'pm,': 0.16; 'def': 0.16; 'header:In-Reply- To:1': 0.22; 'calls.': 0.23; 'raise': 0.28; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'correct': 0.29; 'updated': 0.29; 'lines': 0.31; 'shows': 0.32; 'to:addr:python-list': 0.34; "isn't": 0.35; 'skip:o 20': 0.36; 'some': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; '8bit%:5': 0.38; 'should': 0.39; 'processing': 0.39; 'data': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'reset': 0.40; 'back': 0.63; 'subject:Possible': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=GZSraFnbLXCcKaANnjH1snXVMHDv6SE9WqVRHQfn0vw=; b=xtZ2Sr5TVnry0BBqa9waO/QKiv2E3Hy1jCC19oOuZ3vufHxRhFPU/y61hixYWOMi9H /yXN8fh7kPSs83r3cvo7y4SynL3YDBEGBTOF7k1MO4P4gaBzlYNvFHuKm4TT30+qwxfE SMRvsjYqlWb1oBa5k3Rk5VQUiCynoFhkvnLMs= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 14 Jul 2011 14:00:06 -0600 Subject: Re: Possible File iteration bug To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310673638 news.xs4all.nl 23902 [2001:888:2000:d::a6]:35681 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9485 On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: > def getLines(f): > =A0 =A0lines =3D [] > =A0 =A0for line in f: > =A0 =A0 =A0 =A0lines.append(line) > =A0 =A0return lines > > with open('/var/log/syslog', 'rb') as f: > =A0 =A0lines =3D getLines(f) > =A0 =A0# do some processing with lines > =A0 =A0# /var/log/syslog gets updated in the mean time > > =A0 =A0# always returns an empty list, even though f has more data > =A0 =A0lines =3D getLines(f) > > > > > I found a workaround by adding f.seek(0,1) directly before the last > getLines() call, but is this the expected behavior? =A0Calling f.tell() r= ight > after the first getLines() call shows that it isn't reset back to 0. =A0I= s > this correct or a bug? This is expected. Part of the iterator protocol is that once an iterator raises StopIteration, it should continue to raise StopIteration on subsequent next() calls.