我有点卡住了
我想知道如何从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.ErrorCode += s
很有道理。代码是一个元组,包含类代码的对象。现在,如果您想添加新的代码对象,您需要执行类似于Codes += Code(string, error_code)
的操作但是,Tuples是不可变的。一旦元组被创建,就不能从元组中添加/删除内容。但是,您可以使用列表
相关问题 更多 >
编程相关推荐