A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-September/074733.html below:

[Python-Dev] Iterating over objects of unknown length

[Python-Dev] Iterating over objects of unknown length [Python-Dev] Iterating over objects of unknown lengthPhillip J. Eby pje at telecommunity.com
Wed Sep 26 18:33:33 CEST 2007
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 if it will
>produce any row the class doesn't implement __len__(). Moreover, users of
>the class sometimes write
>
>if sqlQuery:
>    for row in sqlQuery: ...
>else:
>    # no rows

This isn't consistent with iterators; e.g.:

 >>> x=iter([])
 >>> if x: print "yes"
...
yes

ISTM that you should be returning "True" from __nonzero__, since you 
don't implement len().


>1. Should I consider this a bug in the logging module (and other libraries)
>    and submit patches?
>2. Or should I stop raising exceptions in __nonzero__()?

#2 - Python objects should always be __nonzero__, unless they are 
empty containers, zeros, or otherwise specifically False.  It's 
reasonable for libraries to expect that truth-testing an object is always safe.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4