Welcome, guest | Sign In | My Account | Store | Cart
# direct, naive approach -- doesn't work...:
class Class1:
    def static1(name):
        print "Hello",name

# ...but now, a call such as:
# will fail with a TypeError, as 'static1' has become 
# an unbound-method object, not a plain function.

# This is easy to solve with a simple tiny wrapper:
class Callable:
    def __init__(self, anycallable):
        self.__call__ = anycallable

# toy-example usage:
class Class2:
    def static2(name):
        print "Hi there",name
    static2 = Callable(static2)

# now, a call such as:
# works just fine, and as-expected


  • revision 3 (22 years ago)
  • previous revisions are not available