I'd like to have attribute of class, which stores some function, but this function is not method of the class, it will be called later by other component completely out of scope of the class itself, so class is just container for the attribute with function. But call of this function fails with TypeError: unbound method
def f(x): print x
class A:
not_method = f
A.not_method(10)
Is there any way to suppress this error? The obvious way is to store function warped by some data object, like tuple, but it seems not so elegant.
def f(x): print x
class A:
not_method = (f,)
A.not_method[0](10)
Proposed solution with @staticmethod
is not so cool, cause:
- formally the attribute is not a method at all, it's just attribute with some external function
- @staticmethod
decorator does not work with attribute assignment