Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
Steven D'Aprano wrote: If you want iterator operations similar to itertools, why does this mean you need to replace anything? Just create your own iterators. Or use pre-processing and post-processing to get what you want. Can you show an example of what you would like to happen? Steven,

Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
Christian Heimes wrote: If you *really* need to overwrite __iter__ on your instance rather than defining it on your class, you need to proxy the method call: class MyObject(object): def __iter__(self): return self.myiter() obj = MyObject() obj.myiter = myiter That should

Re: new.instancemethod __iter__

2010-02-07 Thread Steve Holden
Martin Drautzburg wrote: Steven D'Aprano wrote: If you want iterator operations similar to itertools, why does this mean you need to replace anything? Just create your own iterators. Or use pre-processing and post-processing to get what you want. Can you show an example of what you would

Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
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

Re: new.instancemethod __iter__

2010-02-07 Thread Steve Holden
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

new.instancemethod __iter__

2010-02-06 Thread Martin Drautzburg
Hello all When I create an Object and set its __iter__ method from outside s = Sequence #one of my own classes s.__iter__ = new.instancemethod(f,s,Sequence) I get different results, depending on whether I call for x in y.__iter__(): print x or for x in y: print x The first case

Re: new.instancemethod __iter__

2010-02-06 Thread Steven D'Aprano
On Sat, 06 Feb 2010 23:53:53 +0100, Martin Drautzburg wrote: Hello all When I create an Object and set its __iter__ method from outside s = Sequence #one of my own classes s.__iter__ = new.instancemethod(f,s,Sequence) I'm confused as to why you are aliasing your class before changing it.

Re: new.instancemethod __iter__

2010-02-06 Thread Christian Heimes
Martin Drautzburg wrote: The first case does what I expected, i.e. it iterates over whatever f() yields. In the second case nothing is printed. I have the impression that it still calls the original __iter__() method (the one defined at the class level). Why is that so? How can I replace