while (a=b()) ...

scott cotton scott at chronis.pobox.com
Mon May 10 12:57:12 EDT 1999


On Mon, 10 May 1999 14:30:52 GMT, Andrew Csillag <andrew at starmedia.net> wrote:
[..]
>Is this so bad?
>
>c=curs.fetchone()
>while c:
>    do something with c
>    c=curs.fetchone()
>
>Is it a little redundant? Yes.  Error prone?  No.

Error prone it is - by virtue of being redundant. changes to
the loop may require changing two code lines, and it's easy
to forget to update redundant code.

while (c=curs.fetchone(); c):

is not redundant, nor does it have the '=' != '==' problem.

scott




More information about the Python-list mailing list