del(instance.attr) -- no attribute
cliechti at gmx.net
Sun Sep 1 17:32:58 EDT 2002
Lee Harr <missive at frontiernet.net> wrote in
news:un512ii7hjgq22 at corp.supernews.com:
> Is this a bug?
>>>> class C:
> ... a = 1
>>>> c = C()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: C instance has no attribute 'a'
>>>> hasattr(c, 'a')
> I can see that maybe del(c.a) should not be allowed to delete
> the attribute, but I think the error message is misleading.
but the message is true. the instance has no attribute named "a", it's an
attribute of the class "C". maybe "hasattr" is missleading to you, because
it's showing class and instace attributes, including those of base classes.
but deleting has to occour in the correct spot.
Chris <cliechti at gmx.net>
More information about the Python-list