Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Iterate over text file, discarding some lines via context manager Date: Fri, 28 Nov 2014 19:55:40 +0200 Organization: A noiseless patient Spider Lines: 20 Message-ID: <87fvd3dxb7.fsf@elektro.pacujo.net> References: <5478ab81$0$2879$426a34cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="725"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+CTFghcRu7nxzZ7d81kf8" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:CB7dLy0P7Y7o4Fc9I7HniLLtxvI= sha1:mk7FoDSVJ9lwKI0QrWCMtQSa3Jw= Xref: csiph.com comp.lang.python:81698 Dave Angel : > Why would you prefer that over a generator function, as given earlier > in the thread? See for example Ned's message. By using 'yield', you > get Python to generate all the class boilerplate for you. I think the OP can learn from the comparison. One question, many lessons: * Here's how you write a generator. * Here's how you write a context manager class. You run into those quite often as well. * See how much more suitable a generator is in this case. No need to shoot down those who only try to be helpful. Marko