4 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Please add some __le...
FromSent OnAttachments
klaus22 Oct 2007 03:32 
King Simon-NFHD7822 Oct 2007 03:46 
Michael Bayer22 Oct 2007 06:37 
klaus23 Oct 2007 01:08 
Subject:[sqlalchemy] Re: Please add some __len__ methods
From:klaus (klau@haufe.de)
Date:10/23/2007 01:08:49 AM
List:com.googlegroups.sqlalchemy

Seems like I am learning more python on this list than I ever wanted...

On 22 Okt., 15:37, Michael Bayer <mike@zzzcomputing.com> wrote:

On Oct 22, 2007, at 6:32 AM, klaus wrote:

Hi all, I wonder why some classes/objects implement part of a list interface - but without a __len__ method. Obvious examples are:

Query has __iter__ and __getitem__, both of which access the database. __len__ would be a nice alternative to a basic count().

can't put __len__ on query for the reasons simon described. would issue COUNT queries for every list() evaluation (which is basically every query). this is a python limitation that theres no way to force list() to use only __iter__ without calling __len__() first.

Session has __iter__ and __contains__. __len__ could be used to indicate when the session gets too large and should be cleared.

persistent, non-dirty objects in the session are weakly referenced in 0.4 and will automatically fall out of scope if not referenced elsewhere. that said, theres no reason __len__() couldnt be on Session anyway.