Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Oscar Benjamin
On 10 February 2013 14:32, Walter Prins wrote: [snip > > This worked mostly fine, however yesterday I ran into a slightly unexpected > problem when I found that when the list contents is iterated over and values > retrieved that way rather than via [], then __getitem__ is in fact *not* > called on

Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Peter Otten
Peter Otten wrote: > def __iter__(self): > for i in range(len(self)): > return self[i] That should of course be 'yield', not 'return' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.pytho

Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Dave Angel
On 02/10/2013 10:10 AM, Dave Angel wrote: On 02/10/2013 09:32 AM, Walter Prins wrote: Hello, I have a program where I'm overriding the retrieval of items from a list. As background: The data held by the lists are calculated but then read potentially many times thereafter, so in order to preve

Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Peter Otten
Walter Prins wrote: > Hello, > > I have a program where I'm overriding the retrieval of items from a list. > As background: The data held by the lists are calculated but then read > potentially many times thereafter, so in order to prevent needless > re-calculating the same value over and over,

Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Steven D'Aprano
On 11/02/13 01:32, Walter Prins wrote: Hello, I have a program where I'm overriding the retrieval of items from a list. As background: [...snip interesting but irrelevant background...] Here's a test application that demonstrates the issue: [...snip overly complicated application...] Her

Re: [Tutor] How to override getting items from a list for iteration

2013-02-10 Thread Dave Angel
On 02/10/2013 09:32 AM, Walter Prins wrote: Hello, I have a program where I'm overriding the retrieval of items from a list. As background: The data held by the lists are calculated but then read potentially many times thereafter, so in order to prevent needless re-calculating the same value o