一种方法是:
def methodA(self):
if doc['flag']:
self.anotherMethod()
def anotherMethod(self):
self.method1()
self.method2()
或者:
def methodB(self, flag=False, execute_anyways=False):
if not flag and not execute_anyways:
return #Note that while calling, you would be sending True, or False. If flag=None, it would execute.
self.method1()
self.method2()
def methodA(self):
self.methodB(flag=doc['flag'])
在另一种情况下,只需调用
self.methodB(execute_anyways=True) #Now, the flag would have the default value of None, and would execute.