[ale] Pyhon syntax
Benjamin Scherrey
scherrey at proteus-tech.com
Tue Jan 25 15:49:04 EST 2005
for row in c.fetchone():
print row
This will iterate through every call until c.fetchone() is empty and
returns None or throws an exception. Python structures loops as
iterations of lists, not too dissimilar from lisp except with a readable
syntax. The result is that you do only have one exit from your loop in
the vast majority of cases, you don't have seperate testing code from
iteration code, and the semantics more closely match your logical
intention. I'm a big C++ programmer but python never fails to astonish
me and being both simple to learn while powerfully expressive at the
same time. I think its fairly unique in that regard. Python is very
object oriented as is C++ but also supports the functional paradigm
which, in C++, requires more clumsy and sometimes brain warping syntax
of predicate templates and function objects.
Ben Scherrey
Christopher Fowler wrote:
>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.
>
>
>
<snip rest>
More information about the Ale
mailing list