'super' object has no attribute '__setitem__'
pwoolcoc at gmail.com
Fri Aug 19 06:14:11 EDT 2011
If you really want __setitem__ and not __setattr__, you should change the
base class to 'dict'. Or 'import UserDict' and use that for the base class.
On Aug 18, 2011 9:45 PM, "luvspython" <srehtvandy at gmail.com> wrote:
> I'm using Python 2.7 and the code below fails at the 'super' statement
> in the __setitem__ function in the HistoryKeeper class. The error is:
> 'super' object has no attribute '_setitem__'
> Can anyone please tell me why and how to fix it? (I've googled
> endlessly and I don't see the problem.)
> [The code will seem silly as it is, because it's pared down to show
> the example. The goal is that multiple classes, like the Vehicle
> class below, will inherit HistoryKeeper. History keeper overloads
> __setitem__ and will eventually keep a running history every time an
> attribute of any of the inheriting classes is changed.]
> Thanks in advance ....
> class HistoryKeeper(object):
> def __init__(self, args):
> for arg, value in args.items():
> if arg != 'self':
> self.__setitem__(arg, value)
> def __setitem__(self, item, value):
> super(HistoryKeeper, self).__setitem__(item, value)
> class Vehicle(HistoryKeeper):
> def __init__(self, tag, make, model):
> args = locals()
> super(Vehicle, self).__init__(args)
> if __name__ == "__main__":
> car = Vehicle('TAG123', 'FORD', 'Model A')
> print car.make
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list