Reputation: 11921
Am I correct in assuming that an object in Python has a default implementation of all magic methods (the ones surrounded by the double underscore, such as __init__
)?
Upvotes: 3
Views: 213
Reputation: 281653
No.
>>> object.__add__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'object' has no attribute '__add__'
Some of them do have default implementations, like __init__
, but most of them don't.
Upvotes: 6
Reputation: 3709
No it does not have default implementations of all the magic functions.
It would be only true if all the objects were inherited from a common default base class.
There are different classes and different implementation of these classes require different magic functions.
Do object.__class__
to get the class name
To find out all the functions in that object you can do dir(object)
More - http://docs.python.org/release/2.5.2/ref/node33.html
Upvotes: -1