Python - Exists a function that is called when an object does not implement a function?

function, oop, python

Solution

Here is a proposition for what you want to do:

class callee:
    def __init__(self, name):
        self.name = name

    def __call__(self):
        print self.name, "has been called"


class A:
    def __getattr__(self, attr):
        return callee(attr)

a = A()

a.DoSomething()
>>> DoSomething has been called

Problem

In Smalltalk there is a message `DoesNotUnderstand` that is called when an object does not understand a message (this is, when the object does not have the message sent implemented). So, I like to know if in python there is a function that does the same thing. In this example: ``` class MyObject: def __init__(self): print "MyObject created" anObject = MyObject() # prints: MyObject created anObject.DoSomething() # raise an Exception ``` So, can I add a method to `MyObject` so I can know when `DoSomething` is intented to be called? PS: Sorry for my poor English.

Original source