7
7stud
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.
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.