This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task: | |
def __init__(self, title, depencies): | |
self.title = title | |
self.__depencies = depencies | |
def execute(self): | |
plan = [] | |
if self.__depencies: | |
plan += self.__depencies | |
for dep in self.__depencies: | |
# if dep.execute(): | |
# try: | |
# index = plan.index(dep.execute()[0]) | |
# except ValueError: | |
# index = len(plan) - 1 | |
# for x in dep.execute(): | |
# plan.insert(index, x) | |
# # plan.insert(index, ) | |
# plan = + plan | |
plan = dep.execute() + plan | |
# print('Call execute in {}, returned = {}'.format(self.title, [x.title for x in plan])) | |
return plan | |
def depencies(self): | |
return self.__depencies | |
def __str__(self): | |
return self.title | |
# Одинаковые задачи | |
born = Task('born', []) | |
school = Task('school', [born]) | |
graduate = Task('graduate', [school]) | |
get_friends = Task('get_friends', [born, school]) | |
get_cash = Task('get_cash', [school, graduate, get_friends]) | |
buy = Task('buy', [school, graduate, get_cash]) | |
getup = Task('getup', []) | |
cook = Task('cook', [buy, getup]) | |
print('{} → {}'.format([x.title for x in cook.execute()],cook.title)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment