[SOLVED] TypeError: iter() returned non-iterator of type 'RevertableList'
Posted: Thu Oct 27, 2022 8:37 pm
I'm trying to make a class that can be iterated over like a list, but I'm not sure how to properly implement __iter__ and __next__.
However, when I try to run it, I get the error message in the title.
From my understanding, RevertableList is a special Ren'Py list that works with rollback, but still has the properties of a normal list. If that's the case though, I'm not sure why python wouldn't see it as an iterable.
Code: Select all
class Party():
"""A group of units that fight on the same team, either friend or foe."""
def __init__(self,*units):
"""Takes Unit instances and makes a list of them in the team variable"""
self.team = units if isinstance(units,list) else [units]
self.index = 0
def __call__(self):
"""Lets instances of this class be called directly to get the list of party members"""
return self.team
def __iter__(self):
"""Makes this class iterable"""
return self.team
def __next__(self):
"""Handles how the iterator moves through the class's party members"""
if self.index >= len(self.team):
raise StopIteration
else:
self.index += 1
return self.team[index-1]
###Class continues###
From my understanding, RevertableList is a special Ren'Py list that works with rollback, but still has the properties of a normal list. If that's the case though, I'm not sure why python wouldn't see it as an iterable.