[ale] Pyhon syntax

Christopher Fowler cfowler at outpostsentinel.com
Tue Jan 25 14:49:01 EST 2005


I'm playing around with Python and having some issues with the syntax.
Guido van Rossum must hate the syntax of C, Java, Perl, etc.  I'm so
used to braces that I'm getting a headache trying to understand the
syntax.

I'm playing with MySQL DB and am executing some queries.

>>> import MySQLdb
>>> db=MySQLdb.connect(host="127.0.0.1", user="cms", passwd="cms",
db="AC_OUTPOST");
>>> c = db.cursor();
>>> c.execute("SELECT * FROM ens;");
5L
>>>               

What I am wanting to do is a while loop to fetch each row.  I assume I
use the fetchone method of the DB API.
>>> while row=c.fetchone():
  File "<stdin>", line 1
    while row=c.fetchone():
             ^
SyntaxError: invalid syntax
>>> 

Everytime I see a while loop in examples I see a "while 1:"  Then to 
get out of the loop I see a break.  What is the proper syntax?

Thanks,
Chris




More information about the Ale mailing list