defining a method that could be used as instance or static method

Sam samuel.progin at gmail.com
Mon Mar 10 11:39:21 EDT 2008


Hello

I would like to implement some kind of comparator, that could be
called as instance method, or static method. Here is a trivial pseudo
code of what I would like to execute

>> class MyClass:
...    def __init__(self, value):
...        self.value = value
...    def comp(self, compValue):
...        return self.value == compValue.value
>> a = MyClass(3)
>> b = MyClass(4)
>> c = MyClass(3)
>> a.comp(b)
False
>> a.comp(c)
True

This is actually achieved by MyClass, how could implement it in order
to accept:

>> MyClass.comp(a, b)
False

I would really appreciate a pointer or a way to complete MyClass in
order to fulfill my requirements. Thank you for your attention.

Sam



More information about the Python-list mailing list