class AppendiveDict(c.OrderedDict):
def __init__(self,func,*args):
c.OrderedDict.__init__(args)
def __setitem__(self, key, value,):
if key in self:
self[key] = func(self[key])
else:
c.OrderedDict.__setitem__(self,key,value)
我有一个类,它应该将func函数应用于字典中已经存在的项。如果我做了c.OrderedDict.__init__(args)
,它告诉我描述符__init__
需要一个ordereddict而不是元组。你知道吗
如果我更改c.OrderedDict.__init__(self)
,则表示中会显示一个空的orderedict。你知道吗
解决方案是传递这两个参数,因为
c.OrderedDict.__init__
需要知道它应该在哪个实例上操作以及使用哪个参数:或者只将
super
与args
一起使用(因为super
返回一个绑定方法,该方法已经知道在哪个实例上调用它):相关问题 更多 >
编程相关推荐