Arent these snippets equivalent?

John Gordon gordon at
Wed Jan 23 23:06:24 CET 2013

In <d7191cec-d963-42c8-90ba-db6d1359ceeb at> Coolgg <gauravj123 at> writes:

> Is this:

> while True:
>     data =
>     if not data:
>         break
>     ...

> not equivalent to this:

> data = (4096)
> while data:
>     ...{handle the chunk here}
>     data = (4096)

It looks equivalent to me (in terms of control flow).

But in the second example the statement is duplicated, which is
undesirable.  It would be all too easy for a maintenance programmer to go
into the code a year from now and change the first one but miss the second

John Gordon                   A is for Amy, who fell down the stairs
gordon at              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

More information about the Python-list mailing list