Attributeerror: 'list' Object Has No Attribute 'display' In Python
Error comes when i call the display function using class object What should i do to overcome this ?? class A: def __init__(self, fname, lname, age): self.fname = fname
Solution 1:
You have a list of instances called a
. a
isn't the instance/s, it's a list.
You probably meant to do:
for myobject in a:
myobject.disply() # Note "disply" instead of "display"
Solution 2:
a = [A("Taylor","Launter",22), A("James","bond",40)]
a.display()
Now a
is a list. Lists in python dont have display
method.
What you might actually have wanted to do is to invoke display
method of the object of A
. If that is the case, you might want to do something like this
for currentObject in [A("Taylor","Launter",22), A("James","bond",40)]:
currentObject.display()
Edit Your display
method doesnt make any sense to me.
Post a Comment for "Attributeerror: 'list' Object Has No Attribute 'display' In Python"