staticmethod and setattr
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Mon Mar 15 06:40:31 EDT 2010
On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote:
> Hi,
>
> 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" i tried:
> class Foo(object):
> @staticmethod
> def _ref(o):
> pass
>
> setattr(Foo, "$ref", Foo._ref)
That doesn't work as expected:
>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref']
False
Try this instead:
>>> setattr(Foo, "$ref", Foo.__dict__['_ref'])
>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref']
True
--
Steven
More information about the Python-list
mailing list