Matt Good wrote:
> This seems like a good place for a for/else:
> 
> for p in Person.select(Person.q.org == 'foo.com'):
>     print p.name
> else:
>     print "No records found."

No, this a common misconception about the "else" clause of the Python
"for" contruct! The "else" clause is always executed after the iteration
of the "for" loop is exhausted, _unless_ you break out from it with a
"break" or "return".

http://www.python.org/doc/current/ref/for.html (first two paragraphs)

So, in this example, if the result set was not empty, it would print

<name 1>
<name 2>
.
.
.
<name n>
No records found.

Which was certainly not intended.

Chris


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to