我得到这个错误
File "/class.py", line 246, in __init__
if d and self.rf == 2 and d["descriptionType"] in ["900000000000003001"] and d["conceptId"] in konZer.zerrenda:
TypeError: 'Desk' object is not subscriptable
我创建了这个对象
class Desk:
descriptionId = ""
descriptionStatus = ""
conceptId = ""
term = ""
我在另一个班叫它
class DescriptionList():
def deskJ(self,line):
er = line.strip().split('\t')
desc = Desk()
if er[1] == "0":
desc.descriptionId = er[0]
desc.descriptionStatus = er[1]
desc.conceptId = er[2]
desc.term = er[3]
return description
然后我在init调用函数“deskJ”,得到这部分的错误(我删除了函数的一些部分):
def __init__(self,fitx,konZer,lanZer={}):
with codecs.open(fitx,encoding='utf-8') as fitx:
lines = fitx.read().split('\n')[1:-1]
for line in lines:
d = self.deskJ(line)
if d and self.rf == 2 and d["descriptionType"] in ["900000000000003001"] and d["conceptId"] in konZer.zerrenda:
c = konZer.zerrenda[d["conceptId"]]
c["fullySpecifiedName"] = d["term"]
我做错什么了?
使用
d["descriptionType"]
试图用键"descriptionType"
访问d
。但这不起作用,因为d
是一个没有键的Desk
对象。相反,获取属性:相关问题 更多 >
编程相关推荐