<div>I'm pretty sure I'd actually read the first 2 links you point to, but the difference between __setattr__ and __setitem__ still never registered with me -- perhaps partly because even the discussion of __setattr__ discusses adding an entry to the  "<u>dictionary</u> of instance attributes".</div>
<div> </div><div><u><strong>MANY</strong></u> thanks for your help!</div><div> </div><div> </div><div> </div>
<div> </div><div><br><br> </div><div class="gmail_quote">On Thu, Aug 18, 2011 at 10:07 PM, Eric Snow <span dir="ltr"><<a href="mailto:ericsnowcurrently@gmail.com" target="_blank">ericsnowcurrently@gmail.com</a>></span> wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">
<div><div></div><div>On Thu, Aug 18, 2011 at 7:44 PM, luvspython <<a href="mailto:srehtvandy@gmail.com" target="_blank">srehtvandy@gmail.com</a>> wrote:<br>
> 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>
</div></div>Did you mean to use __setattr__ instead?  object, the base class of<br>
HistoryKeeper, does not have a __setitem__ method, hence the<br>
AttributeError.  super() is a proxy for the next class in the MRO,<br>
typically the base class of your class.<br>
<br>
Keep in mind that <obj.tag = "TAG123"> is equivalent to<br>
<obj.__setattr__("tag", "TAG123")>.  However, <obj["tag"] = "TAG123"><br>
is equivalent to <obj.__setitem__("tag", "TAG123")>.<br>
<br>
see:<br>
<br>
<a href="http://docs.python.org/reference/datamodel.html#object.__setattr__" target="_blank">http://docs.python.org/reference/datamodel.html#object.__setattr__</a><br>
<a href="http://docs.python.org/reference/datamodel.html#object.__setitem__" target="_blank">http://docs.python.org/reference/datamodel.html#object.__setitem__</a><br>
<a href="http://docs.python.org/library/functions.html#super" target="_blank">http://docs.python.org/library/functions.html#super</a><br>
<br>
-eric<br>
<br>
> --<br>
> <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
><br>
</blockquote></div><br>