staticmethod and namespaces

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Feb 26 08:12:48 CET 2010


On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote:

> Having an odd problem that I solved, but wondering if its the best
> solution (seems like a bit of a hack).
> 
> First off, I'm using an external DLL that requires static callbacks, but
> because of this, I'm losing instance info.
[...]
> How can I get at the app instance (currently I'm storing that along with
> the class instance in the constructor)? Is there another way to do this
> that's not such a hack?

Pass the instance explicitly:

>>> class K(object):
...     @staticmethod
...     def static(self, x, y):
...         print self, x, y
...
>>> k = K()
>>> k.static(k, 1, 2)
<__main__.K object at 0xb7c2544c> 1 2


-- 
Steven



More information about the Python-list mailing list