[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Tue Jan 25 15:04:06 2005 -->
- <!--x-from-r13: psbjyre ng bhgcbfgfragvary.pbz (Quevfgbcure Tbjyre) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Pyhon syntax -->
- <li><em>date</em>: Tue Jan 25 15:04:06 2005</li>
- <li><em>from</em>: cfowler at outpostsentinel.com (Christopher Fowler)</li>
- <li><em>in-reply-to</em>: <<a href="msg01066.html">[email protected]</a>></li>
- <li><em>references</em>: <<a href="msg01066.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Pyhon syntax</li>
>>> 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
> <a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="01078" href="msg01078.html">[ale] Pyhon syntax</a></strong>
<ul><li><em>From:</em> scherrey at proteus-tech.com (Benjamin Scherrey)</li></ul></li>
<li><strong><a name="01080" href="msg01080.html">[ale] Pyhon syntax</a></strong>
<ul><li><em>From:</em> jpheale at LearnLink.Emory.Edu (John P. Healey)</li></ul></li>
<li><strong><a name="01082" href="msg01082.html">[ale] Pyhon syntax</a></strong>
<ul><li><em>From:</em> jpheale at LearnLink.Emory.Edu (John P. Healey)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="01066" href="msg01066.html">[ale] Pyhon syntax</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg01067.html">[ale] Critters in the Attic</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg01069.html">[ale] Subversion usage</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg01066.html">[ale] Pyhon syntax</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg01078.html">[ale] Pyhon syntax</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#01068"><strong>Date</strong></a></li>
<li><a href="threads.html#01068"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>