我正在尝试创建一个显示有关每个元素的各种信息的化学 GUI。我正在使用类实例列表来打印信息,但我继续得到一个'list' object has no attribute 'atomic_number'
. 这是我设置的类,以及给我错误的代码。
class ElementInformation(object):
def __init__(self, atomic_number, element_name, element_symbol, atomic_weight, melting_point, boiling_point)
self.atomic_number = atomic_number
self.element_name = element_name
self.element_symbol = element_symbol
self.atomic_weight = atomic_weight
self.melting_point = melting_point
self.boiling_point = boiling_point
def find_element():
update_status_label(element_information, text_entry)
# text entry is a text entry field in TKinter
# other code in here as well (not part of my question
def update_status_label(element_instances, text_input):
for text_box in element_instances.atomic_number:
if text_input not in text_box:
# do stuff
else:
pass
element_result_list = [*results parsed from webpage here*]
row_index = 0
while row_index < len(element_result_list):
element_instances.append(ElementInformation(atomic_number, element_name, element_symbol, atomic_weight, melting_point, boiling_point))
# the above information is changed to provide me the correct information, it is just dummy code here
row_index += 1
我的问题在于函数update_status label
,特别是for
循环。Python 抛出一个错误(就像我之前说的),上面写着'list' object has no attribute 'atomic_number'
. 对于我的生活,我似乎无法弄清楚出了什么问题。谢谢你的帮助!
如果有什么不同,我在 Windows 上使用 Python 3.x