new.instancemethod __iter__

Martin Drautzburg Martin.Drautzburg at web.de
Sun Feb 7 09:50:53 EST 2010


Steve Holden wrote:


>> y = s1*2 + s2(align=10)
>> 
>> which should iterate as
>> 
>> Time=1,'a'
>> Time=2,'a'
>> Time=10,'b'
>> 
>> I have no difficulty passing "align" to the object (using __call__)
>> and use it while I furnish my own __iter__() method. However I don't
>> quite see how I can do this with bare itertools, though I may be
>> wrong here.
>> 
>> Bare in mind that it is not only about somehow getting the job done.
>> The beauty of the resulting syntax is also important.
>> 
> In that case why not just assume that the timing of a sequence is
> relative to the current time unless the "align" argument is given?

Well that's pretty much what I'm doing. I just fail to see how I can do
this with bare itertools. Currently I am doing it in the following way:

When I call a Sequence as in s2(align=2) I create a new Sequence where
the "align" value is simply stored in an instance variable. 

When creating the sum of two sequences, I create a Sequence with a new
iter() method which first iterates over self and then over the second
Sequence. But each time it has to look up the "align" value of the
respective sequence and adjust "time" accordingly. 

Appending the two Sequences is the easy part, but adjusting time is the
difficult part. My impression was, that itertools can only help to
solve the first part.

I may be missing something obvious. If that's the case, please let me
know.









More information about the Python-list mailing list