Python : How to intercept a method call which does-not exists?
Posted
by
Yugal Jindle
on Stack Overflow
See other posts from Stack Overflow
or by Yugal Jindle
Published on 2012-06-04T10:26:29Z
Indexed on
2012/06/04
10:40 UTC
Read the original article
Hit count: 167
python
I want to create a class that doesn't gives an Attribute Error
on call of any method that may or may not exists:
My class:
class magic_class:
...
# How to over-ride method calls
...
Expected Output:
ob = magic_class()
ob.unknown_method()
# Prints 'unknown_method' was called
ob.unknown_method2()
# Prints 'unknown_method2' was called
Now, unknown_method
and unknown_method2
doesn't actually exists in the class, but how can we intercept the method call in python ?
© Stack Overflow or respective owner