Re: [Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Oleg Broytmann
On Thu, Sep 27, 2007 at 01:33:47PM +1200, Greg Ewing wrote: > Oleg Broytmann wrote: > >if sqlQuery: > > for row in sqlQuery: ... > >else: > > # no rows > > > >To prevent users from writing such code the class implements __nonzero__() > >that always raises an exception. > > I'm not sure I like

Re: [Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Greg Ewing
Oleg Broytmann wrote: > Hello! > >(This seems like a "developing with Python" question and partially it is > but please read on.) > >I have a class that represents SQL queries. Instances of the class can > be iterated over. ... users of > the class sometimes write > > if sqlQuery: >f

Re: [Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Oleg Broytmann
On Wed, Sep 26, 2007 at 09:29:10AM -0700, Guido van Rossum wrote: > But I also fail to see why you would be so draconian as to disallow > truth testing of a query altogether. Your query looks like an > iterator. There are tons of other iterators in the language, library > and 3rd party code, and it

Re: [Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Phillip J. Eby
At 07:24 PM 9/26/2007 +0400, Oleg Broytmann wrote: >Hello! > >(This seems like a "developing with Python" question and partially it is >but please read on.) > >I have a class that represents SQL queries. Instances of the class can >be iterated over. As an SQL query doesn't know in advance i

Re: [Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Guido van Rossum
The logging code looks archaic: IMO it should be: if args and len(args) == 1 and isinstance(args[0], dict) and args[0]: But I also fail to see why you would be so draconian as to disallow truth testing of a query altogether. Your query looks like an iterator. There are tons of other iterators i

[Python-Dev] Iterating over objects of unknown length

2007-09-26 Thread Oleg Broytmann
Hello! (This seems like a "developing with Python" question and partially it is but please read on.) I have a class that represents SQL queries. Instances of the class can be iterated over. As an SQL query doesn't know in advance if it will produce any row the class doesn't implement __len_