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: 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 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 Subject: Re: Arent these snippets equivalent? References: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig5CBB03B20AA3CEE1225D0526 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 01/23/2013 03:56 PM, Coolgg wrote: > Is this: >=20 > while True: > data =3D fp.read(4096) > if not data: > break > ... >=20 > not equivalent to this: >=20 > data =3D fp.read (4096) > while data: > ...{handle the chunk here} > data =3D fp.read (4096) >=20 > 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 --------------enig5CBB03B20AA3CEE1225D0526 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJRAG+jAAoJEAOzoR8eZTzgfqcH/jkzORjA64IPtyrPTPn61Owh Ng7xsU4pNxUKiJR0qFZXfmG5XTIgmKqBq9+so4ZcuL0c1xqlKNCTbFj+xngd20pZ av3UT65cqxnmaw8E5FNQliUFCm+d07ewMoFRyEM0c8J7xMTN8q3mo5WEC9XfQIJ9 km59y2CV363Cs7DA5nAKTTn/sEUCmYogybnLooz6PUQInse1MBmRveuvEr6z7g/Y o5Wb3PxNWKM1UILEltaFOFe3TXqnUfOfWyNDqUrbATDIeMWsaA8ykcUQb0YzPMN7 IeQG5xz/myalNuMgQpUh5r1LAAcwUHP5ThG2K1PCjXodrnRN4Km8jABPZKAMuzI= =9uJn -----END PGP SIGNATURE----- --------------enig5CBB03B20AA3CEE1225D0526--