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


Groups > comp.lang.python > #37516

Re: Arent these snippets equivalent?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <driscoll@cs.wisc.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'chunk': 0.07; 'data:': 0.07; 'python': 0.09; 'cc:addr:python-list': 0.10; '"..."': 0.16; '"are': 0.16; 'filename:fname piece:signature': 0.16; 'subject:these': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'equivalent': 0.20; 'cc:2**0': 0.23; 'statement': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'question:': 0.29; 'no,': 0.29; 'code': 0.31; 'not.': 0.32; 'pm,': 0.35; 'subject:?': 0.35; 'there': 0.35; 'url:org': 0.36; 'skip:p 20': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'matter': 0.61; 'lower': 0.61; 'legal': 0.65; 'upper': 0.75; 'article': 0.78
Date Wed, 23 Jan 2013 17:17:45 -0600
From Evan Driscoll <driscoll@cs.wisc.edu>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130108 Thunderbird/10.0.12
MIME-Version 1.0
To Coolgg <gauravj123@gmail.com>
Subject Re: Arent these snippets equivalent?
References <d7191cec-d963-42c8-90ba-db6d1359ceeb@googlegroups.com>
In-Reply-To <d7191cec-d963-42c8-90ba-db6d1359ceeb@googlegroups.com>
X-Enigmail-Version 1.4
Content-Type multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig5CBB03B20AA3CEE1225D0526"
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.929.1358983138.2939.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358983138 news.xs4all.nl 6902 [2001:888:2000:d::a6]:38321
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37516

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 01/23/2013 03:56 PM, Coolgg wrote:
> Is this:
> 
> while True:
>     data = fp.read(4096)
>     if not data:
>         break
>     ...
> 
> not equivalent to this:
> 
> data = fp.read (4096)
> while data:
>     ...{handle the chunk here}
>     data = fp.read (4096)
> 
> Heres the article that sparked this question:
> http://wordaligned.org/articles/pythons-lesser-known-loop-control

There is at least one potentially-critical difference: what happens if
there is a 'continue' statement in the "..." part. The upper loop will
set data again, while the lower one will not.

So if what you mean is "are they equivalent no matter what legal Python
code you put in the ...", no, they aren't.

Evan

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


Thread

Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 13:56 -0800
  Re: Arent these snippets equivalent? John Gordon <gordon@panix.com> - 2013-01-23 22:06 +0000
  Re: Arent these snippets equivalent? Chris Angelico <rosuav@gmail.com> - 2013-01-24 09:13 +1100
    Re: Arent these snippets equivalent? Roy Smith <roy@panix.com> - 2013-01-23 17:47 -0500
      Re: Arent these snippets equivalent? Tim Chase <python.list@tim.thechases.com> - 2013-01-23 17:29 -0600
      Re: Arent these snippets equivalent? Chris Angelico <rosuav@gmail.com> - 2013-01-24 10:29 +1100
      Re: Arent these snippets equivalent? Terry Reedy <tjreedy@udel.edu> - 2013-01-23 21:38 -0500
        Re: Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 21:01 -0800
        Re: Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 21:01 -0800
  Re: Arent these snippets equivalent? Evan Driscoll <driscoll@cs.wisc.edu> - 2013-01-23 17:17 -0600

csiph-web