what should I do when I would like to return object from class and at the same time can print this result.
I did this:
class Engine:
def __init__(self, mylist):
self._mylist = list(mylist)
def __str__(self) -> str:
return ','.join(el.__str__() for el in self._mylist)
def __repr__(self):
return self._mylist
but when I do:
p = Engine(lst)
print(p)
for x in p:
print("Element", x)
I get:
element1, element2, element3
TypeError: 'Engine' object is not iterable
What should I do to have possibility to print this result and also iterate over it just like the object?