class Analysis:
def __init__(self):
self.step_list = []
self.index = -1
# self.iter = True
# def __repr__(self):
# return f""
def __str__(self):
return f"<class> 'Analysis'"
def build_step_list(self, step: Step):
self.step_list.append(step)
def __iter__(self):
# self.iter = iter(self.step_list)
return self
def __next__(self):
if self.index <= len(self.step_list) - 2 and len(self.step_list) > 0:
self.index += 1
# yield self.step_list[self.index]
# next(self.step_list[self.index])
return self.step_list[self.index]
else:
# del self.iter
self.index = -1
raise StopIteration
python类的迭代器
于 2023-03-20 19:20:22 首次发布