Python - Dictionary - Modify __getitem__?

前端 未结 2 962
天命终不由人
天命终不由人 2021-01-06 17:45

Ok so i\'ve build my own variable handler which has a __getitem__ function for use when accessing data via data[key], it works great except for when trying to a

2条回答
  •  醉梦人生
    2021-01-06 18:14

    Remember: tmp = foo['bar']['baz'] is the same as tmp = foo['bar']; tmp = tmp['baz']

    So to allow arbitrary depths your __getitem__ method must return a new object that also contains such a __getitem__ method.

提交回复
热议问题