[ale] Pyhon syntax
Christopher Fowler
cfowler at outpostsentinel.com
Tue Jan 25 15:04:06 EST 2005
The Python fact seems to explain these differences.
>>> while True:
... row = c.fetchone();
... if not row: break;
... print row
This one works but goes against the idea that if you enter a loop there
must only be one way out of that loop.
On Tue, 2005-01-25 at 14:44, Christopher Fowler wrote:
> 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
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list