new.instancemethod __iter__

Steve Holden steve at holdenweb.com
Sun Feb 7 10:10:15 EST 2010


Martin Drautzburg wrote:
> 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.
> 
Perhaps I am assuming too much of your simulation environment/player.

I presumed that there would be a global "current time" value that would
be passed into or available to the play method of the sequences. However
I can see that you might need something more complex if (e.g.) you want
to be able to start playing at an arbitrary point in time.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list