반응형
이 오류가 발생했습니다.
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
객체이기 때문에 작동하지 않습니다. 대신 다음 속성을 가져 오십시오.
if d and self.rf == 2 and d.descriptionType in ["900000000000003001"] and d.conceptId in konZer.zerrenda:
참조 페이지 https://stackoverflow.com/questions/36335328
반응형
'파이썬' 카테고리의 다른 글
파이썬 matplotlib 오류-tkinter라는 모듈이 없습니다. (0) | 2020.11.05 |
---|---|
파이썬 List Comprehension을 사용한 중첩 For 루프 (0) | 2020.11.05 |
파이썬 Weekday int에서 요일 이름 가져 오기 (0) | 2020.11.05 |
파이썬 IPython 노트북 ipywidgets가 표시되지 않음 (0) | 2020.11.05 |
파이썬 SFTP를 사용하는 Paramiko의 SSHClient (0) | 2020.11.05 |
댓글