Other notes

Paul Rubin http
Tue Dec 28 23:20:17 EST 2004


Andrew Dalke <dalke at dalkescientific.com> writes:
> What does
>   a = MyClass()
>   b = AnotherClass()
>   for x in a .. b:
>     print x
> 
> do?  That is, what's the generic protocol?  

".." just becomes an operator like + or whatever, which you can define
in your class definition:

    class MyClass:
       def __dotdot__(self, other):
          return xrange(self.whatsit(), other.whatsit())

The .. operation is required to return an iterator.



More information about the Python-list mailing list