I'd like to hold reference to callback functions in a singleton. However, python does some magic (either at the point of assignment or at the point of calling), that means the function requires an instance object as the first parameter -- I want to be able to store a simple function. How can I do this?
Assigning to X.__dict__ has the same effect.
def default(): print "default"
class X:
func = None
@staticmethod
def setup(f=default):
X.func = f
@staticmethod
def doit():
if X.func is None: X.setup()
# !!!!!!!
# TypeError: unbound method g() must be called with X instance as first argument (got nothing instead)
X.func()
def g(): print "g"
X.setup(g)
X.doit()
Xexist at all? Why did you define a class for this, especially if you're not going to make instances of the class?