Python __str__ and lists
Calling string on a python list calls the __repr__
method on each element inside. For some items, __str__
and __repr__
are the same. If you want that behavior, do:
def __str__(self):
...
def __repr__(self):
return self.__str__()
You can use a list comprehension to generate a new list with each item str()'d automatically:
print([str(item) for item in mylist])