Z
zealalot
So, I'm trying to come up with a way to pass a method (from the same
class) as the default argument for another method in the same class.
Unfortunately though, I keep getting "self not defined" errors since
the class hasn't been read completely before it references itself.
Is there a better way of doing this?
--- CODE ---
class SomeClass():
def doNothing(self):
pass
def function1(self):
print "Running function 1."
def function2(self, passedFunction=self.doNothing):
print "Running passed function."
passedFunction()
someObject = SomeClass()
someObject.function2(someobject.function1)
--- CODE ---
Thanks,
- Zealalot
class) as the default argument for another method in the same class.
Unfortunately though, I keep getting "self not defined" errors since
the class hasn't been read completely before it references itself.
Is there a better way of doing this?
--- CODE ---
class SomeClass():
def doNothing(self):
pass
def function1(self):
print "Running function 1."
def function2(self, passedFunction=self.doNothing):
print "Running passed function."
passedFunction()
someObject = SomeClass()
someObject.function2(someobject.function1)
--- CODE ---
Thanks,
- Zealalot