Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49115
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <wuwei23@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'explicit': 0.07; 'processing.': 0.07; 'stops': 0.07; 'subject:PEP': 0.07; 'function:': 0.09; 'lines.': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'expression.': 0.16; 'wrote:': 0.18; 'file,': 0.19; '8bit%:5': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'load': 0.23; 'header': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '25,': 0.31; 'bad.': 0.31; 'breaking': 0.31; 'file': 0.32; 'another': 0.32; 'checking': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'raising': 0.36; 'possible': 0.36; '8bit%:4': 0.38; '8bit%:6': 0.40; 'even': 0.60; 'expression': 0.60; 'subject:? ': 0.60; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'within': 0.65; 'to:charset:iso-8859-1': 0.74; 'subject:this': 0.83; 'condition.': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=uFK5NItjmw/uqDQImnng2fbxiLQmSMoxE0NVbQTWSpU=; b=CANr0xeUFRYdShLbQbN7tFTPEhMmrrYIu4QpelcpciBJYC2j678OKtlm4OVLYQxngx XnCECHSH2yma5IW0yWECMSbuSvqlMI3zllS0S5EvAhmpNKUZwGXeLPSJim1mm+sdvo4g r+rGwVwPSg23ETkhej2bbztmiP39nDRWFAgldlCS2VLEPRmoXu+PqRzXwvN/l4QvT29D Mo48dnbQiz7Y7ylwOP3YnteC3Ml6/IduYD3OFY1BpZAR8gnvG6PYcpKHqFkkLsCfQGI3 u8hH/5i+u0kky2ERE46781OLYpld3eyEJ9dnmuEIh8jzoXdHkWC4fgQWvi4r0eoKm8j8 hpMA== |
| MIME-Version | 1.0 |
| X-Received | by 10.220.73.135 with SMTP id q7mr12666215vcj.33.1372120873940; Mon, 24 Jun 2013 17:41:13 -0700 (PDT) |
| In-Reply-To | <CAA=1kxR0sMf2MT-UniaVsEY9pUhc0Tvq+O2aHc6ZBY=Gjt1hOg@mail.gmail.com> |
| References | <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <mailman.3760.1372104769.3114.python-list@python.org> <kqajj8$54h$1@dont-email.me> <mailman.3788.1372116912.3114.python-list@python.org> <kqam8g$f7n$1@dont-email.me> <CAA=1kxR0sMf2MT-UniaVsEY9pUhc0Tvq+O2aHc6ZBY=Gjt1hOg@mail.gmail.com> |
| Date | Tue, 25 Jun 2013 10:41:13 +1000 |
| Subject | Re: Is this PEP-able? fwhile |
| From | wu wei <wuwei23@gmail.com> |
| To | Fábio Santos <fabiosantosart@gmail.com> |
| Content-Type | multipart/alternative; boundary=001a11c2917c47c1fe04dfefc9b4 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3791.1372120877.3114.python-list@python.org> (permalink) |
| Lines | 66 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1372120877 news.xs4all.nl 15885 [2001:888:2000:d::a6]:45675 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:49115 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Tue, Jun 25, 2013 at 10:19 AM, Fábio Santos <fabiosantosart@gmail.com>
wrote:
> for X in (i for i in open('largefile') if is_part_of_header(i)):
>
> The above code would be wasting time on IO and processing. It would load
> another line and calculate the condition for every line of the large file
> and I just wanted to loop over the few header lines.
>
> itertools.takewhile and fwhile/for..while actually stops the loop when the
> condition is not meant, while your example keeps checking the condition
> until the end of file, even though it is a generator expression.
>
Ah yes, of course, my bad.
It's still possible by raising a StopIteration within the condition
function:
def is_part_of_header(x):
if header_condition:
return True
else:
raise StopIteration
But yes, by this point any clarity of the generator expression approach
comes with the cost of more explicit setup of the breaking condition.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Is this PEP-able? fwhile Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-24 14:12 -0600
Re: Is this PEP-able? fwhile alex23 <wuwei23@gmail.com> - 2013-06-25 09:14 +1000
Re: Is this PEP-able? fwhile Fábio Santos <fabiosantosart@gmail.com> - 2013-06-25 00:35 +0100
Re: Is this PEP-able? fwhile alex23 <wuwei23@gmail.com> - 2013-06-25 10:00 +1000
Re: Is this PEP-able? fwhile Fábio Santos <fabiosantosart@gmail.com> - 2013-06-25 01:19 +0100
Re: Is this PEP-able? fwhile wu wei <wuwei23@gmail.com> - 2013-06-25 10:41 +1000
Re: Is this PEP-able? fwhile Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-24 22:50 -0600
Re: Is this PEP-able? fwhile rusi <rustompmody@gmail.com> - 2013-06-24 23:04 -0700
csiph-web