AttributeError:“列表"对象在python中没有属性“显示" [英] AttributeError: 'list' object has no attribute 'display' in python
本文介绍了AttributeError:“列表"对象在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
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()
现在a
是一个列表. python中的列表没有display
方法.
Now a
is a list. Lists in python dont have display
method.
您可能真正想做的是调用A
对象的display
方法.如果是这样,您可能想做这样的事情
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()
编辑您的display
方法对我来说没有任何意义.
Edit Your display
method doesnt make any sense to me.
这篇关于AttributeError:“列表"对象在python中没有属性“显示"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文