del(instance.attr) -- no attribute
Chris Liechti
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?
no
>>>> 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)
works
> 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
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list