【发布时间】:2019-12-03 20:18:37
【问题描述】:
我有点卡住了
我想知道如何从 XML 文件中填充我的元组。
这是我目前所拥有的:
from xml.dom import minidom
class Code:
def __init__(self, ErrorCode, Amount):
self.ErrorCode = ErrorCode
self.Amount = Amount
filepath = "D:\V11\Dog"
Codes = (Code('txtPLC_ERROR;A: 16', 0), Code('txtPLC_ERROR;A: 119', 0), Code('txtPLC_ERROR;B: 95', 0))
def readConfig():
xmldoc = minidom.parse(filepath + '\Config.xml')
itemlist = xmldoc.getElementsByTagName('item')
# print(len(itemlist))
# print(itemlist[0].attributes['name'].value)
for s in itemlist:
print("Some Profound text")
Codes.ErrorCode += s
readConfig()
现在我得到这个错误:
File "..\PycharmProjects\ProjectX\Analyze.py", line 32, in readConfig
Codes.Errorcode += s
AttributeError: 'tuple' object has no attribute 'Errorcode'>
请不要因为我很愚蠢就举报这个问题。
【问题讨论】:
-
Codes是一个包含Code类对象的元组。ErrorCode是Code的属性,而不是元组。Codes.Errorcode += s应该做什么? -
嗨!它应该在现有元组中添加一个额外的“ErrorCode”
标签: python for-loop tuples populate