del(instance.attr) -- no attribute

Chris Liechti cliechti at
Sun Sep 1 17:32:58 EDT 2002

Lee Harr <missive at> wrote in 
news:un512ii7hjgq22 at
> Is this a bug?


>>>> class C:
> ...  a = 1
> ... 
>>>> c = C()
>>>> c.a
> 1
>>>> del(c.a)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: C instance has no attribute 'a'
>>>> hasattr(c, 'a')
> 1

yes, but

>>> del(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>

More information about the Python-list mailing list