小编Dom*_*ier的帖子

python TypeError:object不支持索引

这是我的代码中的错误部分:

class Room(object):
    def __init__(self):
        self.hotspots = []
        self.image = []
        self.item = []

    def newhotspot(*args):
        new = {'Name' : None,
               'id' : None,
               'rect' : None,
               'Takeable' : None,
               'Lookable' : None,
               'Speakable' : None,
               'Itemable' : None,
               'Goable' : None}

        for i in args:
            new[i[0]] = i[1]
        new['id'] = len(self.hotspots)
        self.hotspots.append(new)

CityTrader = Room()

CityTrader.newhotspot(('Name', 'Trader'),
                      ('Takeable', 'Yes'))
Run Code Online (Sandbox Code Playgroud)

目标是使用一个字典,将所有键设置为none,但指定的键.但是,当我运行它时,我得到:

[...]line 85 in <module>
('Takeable', 'Yes'))
[...]line 44, in newhotspot
new[i[0]] = i[1]
TypeError : 'Room' object does not …
Run Code Online (Sandbox Code Playgroud)

python typeerror

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

typeerror ×1