Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: object is not subscriptable

I`ve obtain this error

  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

I created this object

class Desk:
     descriptionId = ""
     descriptionStatus = ""
     conceptId = ""
     term = ""

And I called it in another class

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

Then I called the function "deskJ" at init and I get the error at this part (I've deleted some parts of the function):

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"]

What am I doing wrong?

like image 828
AEU Avatar asked Mar 31 '16 13:03

AEU


1 Answers

Using d["descriptionType"] is trying to access d with the key "descriptionType". That doesn't work, though, because d is a Desk object that doesn't have keys. Instead, get the attributes:

if d and self.rf == 2 and d.descriptionType in ["900000000000003001"] and d.conceptId in konZer.zerrenda:
like image 142
zondo Avatar answered Sep 22 '22 10:09

zondo