Python dynamic attribute creation

Ian Kelly ian.g.kelly at gmail.com
Fri Jun 25 15:22:33 EDT 2010


On Fri, Jun 25, 2010 at 12:51 PM, Stephen Hansen
<me+list/python at ixokai.io> wrote:
>> Using assignments to create an attribute hides metaprogramming behide,
>> while using delattr() exposes it.
>
> I don't understand what you're saying here either.

I think he's saying that when an attribute exists in the class
dictionary, assigning that attribute to an instance obscures it, and
deleting that attribute from an instance exposes it.

The point being, I guess, that when an assignment to an instance
attribute is performed in the code, it's not immediately obvious
whether that assignment is updating something already defined in the
class or creating something entirely new.  Whereas deleting an
instance attribute always exposes whatever is already defined at the
class level.

I think the distinction is false, though, since deleting an instance
attribute says nothing about whether that attribute is defined at the
class level to begin with.



More information about the Python-list mailing list