Python 类型错误:';Kon';对象不可下标
我有一个叫做Kon的物体Python 类型错误:';Kon';对象不可下标,python,typeerror,Python,Typeerror,我有一个叫做Kon的物体 class Kon: def __init__(self, cId, isP, fsn = "", snoId = "", synDesc = "", preDesc = ""): self.conceptId = cId self.isprimitive = isP self.fullySpecifiedName = fsn #self.ctv3id = self.snomed
class Kon:
def __init__(self, cId, isP, fsn = "", snoId = "", synDesc = "", preDesc = ""):
self.conceptId = cId
self.isprimitive = isP
self.fullySpecifiedName = fsn
#self.ctv3id =
self.snomedId = snoId
#self.conceptStatus = ""
self.synonymDesc= synDesc
self.preferredDesc = preDesc
这个函数在另一个类中:
class ConceptList():
def sct2fsn(self,sctId):
c = self.zerrenda.get(sctId,'')
if c:
return c["fullySpecifiedName"]
else:
return ""
为什么会出现这种类型的错误
File "/klaseak.py", line 169, in sct2fsn
return c["fullySpecifiedName"]
TypeError: 'Kon' object is not subscriptable
不知何故,您产生了这样的想法:应该像访问字典一样访问对象中的数据
return c["fullySpecifiedName"]
但是您还没有为类实现\uuu getitem\uuu
,因此无法使用[…]
符号从中检索项
您可能只想使用常规属性访问来访问该属性:
return c.fullySpecifiedName
什么是kontzeptuaJaso?