I'm trying to iterate through a list of objects and print out a specific attribute of which they all have.
for example:
class egg:
def __init__(self, spam):
self.spam = spam
x1=egg(1)
x2=egg(2)
x3=egg(3)
eggSalad=[x1,x2,x3]
print(eggSalad[:].spam)
I would like to get:
1
2
3
but recieve the following error:
AttributeError: 'list' object has no attribute 'utility'
I understand why the error is occurring but don't understand how to achieve my goal.
What is the correct way to go about doing this?