__abs(self)__?

Emile van Sebille emile at fenx.com
Fri Mar 1 14:13:00 EST 2002


"Mike Carifio" <carifio.nospam at nospam.usys.com> wrote in message
news:f3Qf8.2391$26.139172 at typhoon.maine.rr.com...
> I'm reading about special method names. __abs__(self), which maps to
the
> abs() method seems unneccessary(?).

(Whoops, it got away from me)

Compare:

class ExampleNumber:
    def __init__(self, initializer):
        self.value = initializer
    def __abs__(self):
        return abs(self.value)

x = ExampleNumber(-1)

print abs(x)

class ExampleNumber:
    def __init__(self, initializer):
        self.value = initializer
    def abs(self):   # name isn't special?
        return abs(self.value)

x = ExampleNumber(-1)
print abs(x)


HTH,
--

Emile van Sebille
emile at fenx.com

---------






More information about the Python-list mailing list