Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-28 Thread Lie Ryan
> > > Just for the sake of argument, here's the principle I'm working > from: > > > > # > lst = range(10) > iterlst = iter(lst) > iterlst.next() > > 0 > for x in iterlst: > > ... if x < 5: > > ... print x > > ... else: > > ... break > > ... > > 1 > > 2 > > 3 >

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-28 Thread Eric Abrahamsen
I finally got my iterator-based version working, only to discover that it's nearly four times slower than the brute-force multiple-loops version I started with! Then I tried just adding an incrementing index to the loop, so that each loop only ran through self.events[last_index:], but that

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Kent Johnson
On Tue, Aug 26, 2008 at 1:24 PM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: > On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: >> If all you want to do with the nested Month, etc is to iterate the >> events in them, you could probably use a shared iterator. It would >> have to be able to push-back

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Alan Gauld
"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote So that's why I'm creating the iterator outside of the while loop in the original code, and then using a repeated for loop with a break to step through all the events only once. Of course, the fact that 5 isn't in there probably points to the sourc

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Eric Abrahamsen
On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: On Tue, Aug 26, 2008 at 1:36 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: So my test case: a Month has a 'child' attribute pointing at Week, which has a 'child' attribute pointing at Day, so they all know what kind of child instances itera

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Kent Johnson
On Tue, Aug 26, 2008 at 1:36 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: > So my test case: a Month has a 'child' attribute pointing at Week, which has > a 'child' attribute pointing at Day, so they all know what kind of child > instances iteration should produce. With nested loops, a Month pro

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
I do apologize for the large quantities of confusing description – articulating the problem here has helped me understand exactly what it is I'm after (though it hasn't improved my code!), and I've got a better grasp of the problem now than I did when I first asked. It isn't so much that I

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Kent Johnson
I'm not following your code very well. I don't understand the relationship between the first loop and the iter_children() function. A couple of things that might help: - Django QuerySets can be qualified with additional tests, so you could have each of your month/week/etc classes have its own corr

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
Okay I think I'm onto something, more iterator-related stuff. If I can make self.events an iterator, then run a for loop on it, breaking out of the loop when the events' date attributes get too high. Then on the next run through, that same for loop should pick up where it left off, right? H

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-24 Thread Eric Abrahamsen
On Aug 24, 2008, at 7:20 PM, Kent Johnson wrote: Forwarding to the list with my reply. Please use Reply All to reply to the list. Grr, sorry, I keep forgetting... On Sun, Aug 24, 2008 at 1:02 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: On Aug 23, 2008, at 11:22 PM, Kent Johnson wrot

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-23 Thread Kent Johnson
On Sat, Aug 23, 2008 at 6:47 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: > At first I thought the bisect module was the way to go, but it is too > tightly tied to integer list indices, and works very awkwardly when > bisecting on datetime attributes. I'm not sure what the problem is with bisect

[Tutor] __iter__ loops, partitioning list among children

2008-08-23 Thread Eric Abrahamsen
Hi, I've got a problem that takes a bit of explaining, but it's relatively simple when you get down to it. This is another django-related thing, but the issue itself is pure python. I made a custom class, called an EventEngine, which represents a span of time. You initialize it with a que