__getitem__, __setitem__ multiple keys Python

两盒软妹~` 提交于 2019-12-05 18:39:28

The dict returned by your __getitem__ has no relation any more with your columns. You'll need to return something that perhaps looks like a dict but maps __setattr__ calls back to your table columns:

class Row(dict):
    def __init__(self, table, index, *args, **kw):
        self._table, self._index = table, index
        super(Row, self).__init__(*args, **kw)

    def __setitem__(self, key, value):
        super(Row, self).__setitem__(key, value)
        self._table.columns[key][self._index] = value

then return that instead of a regular dict:

def getBufferRow(self, index):
   row = {}
   for key in self.columns:
       row[key] = self.columns[key][index]
   return Row(self, index, row)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!