У меня есть код с различными функциями. Внутри одного из них есть условие. Я должен проверить, возникает ли это условие для выполнения другой функции.
Какой правильный способ сделать это? Я пробовал что-то подобное, но это не работает
Пример:
class MyClass:
def thisFunction(self):
try:
"I'm doing things"
except:
self.stop = print("That's already done!")
def thisOtherFunction(self):
"I'm doing things with things done in thisFunction"
s = MyClass()
s.thisFunction()
if self.stop == None:
s.thisOtherFunction()
else:
pass
Большое спасибо!
Обновление
На самом деле это намного проще:
class MyClass:
def thisFunction(self):
try:
"I'm doing things"
except:
self.stop = print("That's already done!")
def thisOtherFunction(self):
try:
"I'm doing things with things done in thisFunction"
except:
pass
s = myClass()
s.thisFunction()
s.thisOtherFunction()
Благодаря примеру Адама Смита я просто не думал об этом. Может быть, это не так уж и элегантно.
Update2
Другой способ - использовать def __init__
таким образом:
class MyClass:
def __init__(self):
self.commandStop = False
def thisFunction(self):
try:
"I'm doing things"
except:
self.commandStop = True
def thisOtherFunction(self):
"I'm doing things with things done in thisFunction"
def conditionToGo(self):
if self.commandStop == False:
print("That's already done!")
else:
s.thisOtherFunction()
s = myClass()
s.thisFunction()
s.conditionToGo()