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
self.lname = lname
self.age = age
def disply(self):
fp = open("abc","r")
for lines in fp:
temp = lines.split(", ")[-1]
fp.close()
print a
a = [A("Taylor","Launter",22), A("James","bond",40)]
a.display()
解决方案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.