manually implementing staticmethod()?
7stud
bbxx789_05ss at yahoo.com
Wed Mar 28 17:01:04 EDT 2007
Hi,
Can someone show me how to manually implement staticmethod()? Here is
my latest attempt:
----------------
def smethod(func):
def newFunc():
pass
def newGet():
print "new get"
newFunc.__get__ = newGet
return newFunc
class Test(object):
def show(msg):
print msg
show = smethod(show)
Test.show("hello")
--------------
...but I keep getting the error:
TypeError: unbound method newFunc() must be called with Test instance
as first argument (got str instance instead)
I think I need to intercept the function's __get__() method in order
to block creation of the method object, which requires that the
unbound method call provide an instance.
More information about the Python-list
mailing list