<p>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.</p>
<div class="gmail_quote">On Aug 18, 2011 9:45 PM, "luvspython" <<a href="mailto:srehtvandy@gmail.com">srehtvandy@gmail.com</a>> wrote:<br type="attribution">> I'm using Python 2.7 and the code below fails at the 'super' statement<br>
> in the __setitem__ function in the HistoryKeeper class. The error is:<br>> 'super' object has no attribute '_setitem__'<br>> <br>> Can anyone please tell me why and how to fix it? (I've googled<br>
> endlessly and I don't see the problem.)<br>> <br>> [The code will seem silly as it is, because it's pared down to show<br>> the example. The goal is that multiple classes, like the Vehicle<br>> class below, will inherit HistoryKeeper. History keeper overloads<br>
> __setitem__ and will eventually keep a running history every time an<br>> attribute of any of the inheriting classes is changed.]<br>> <br>> Thanks in advance ....<br>> <br>> <br>> class HistoryKeeper(object):<br>
> def __init__(self, args):<br>> for arg, value in args.items():<br>> if arg != 'self':<br>> self.__setitem__(arg, value)<br>> <br>> def __setitem__(self, item, value):<br>
> super(HistoryKeeper, self).__setitem__(item, value)<br>> <br>> <br>> class Vehicle(HistoryKeeper):<br>> def __init__(self, tag, make, model):<br>> args = locals()<br>> super(Vehicle, self).__init__(args)<br>
> <br>> <br>> if __name__ == "__main__":<br>> car = Vehicle('TAG123', 'FORD', 'Model A')<br>> print car.make<br>> -- <br>> <a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div>