Overloaded Operators allowed???

Huaiyu Zhu hzhu at knowledgetrack.com
Wed Jul 5 19:51:30 EDT 2000


On Wed, 5 Jul 2000 16:09:41 -0700, Jeff <no_spam at umich.edu> wrote:
>Well yes, that is true, but say I wanted to overload "/" to operate on a
>class such as "cookies".  Can this be done?

This is in the docs.  Like,

class cookies:
    def __div__(self, other): return self.data/other
    def __rdiv__(self, other): return other/self.data

Huaiyu



More information about the Python-list mailing list