staticmethod and setattr
mick.lausch at gmail.com
Mon Mar 15 09:43:02 CET 2010
I managed to get confused by Python, which is not such an easy task.
The problem i have is rooted in marshalling, JSON and Dojo.
I need some static class in function with the name "$ref"
setattr(Foo, "$ref", Foo._ref)
but when i do something like this in code:
b = Bar
f = Foo.getattr("$ref")
if get the following error
unbound method _ref() must be called with Foo instance as first
argument (got Bar instance instead)
I managed to impelemnt it with a unbound, "normal" _ref() function,
but i want one _ref function per
class, because they are a little bit different for each class.
One aproach which i have not tried is:
setattr(Foo, "$ref", Foo._ref.im_func).
maybe this works, but i think this is not a clean aproach.
More information about the Python-list