confused about the different built-in functions in Python

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon May 26 19:14:38 EDT 2014


Marko Rauhamaa wrote:

> IOW, you can override a method with setattr() but you cannot delete a
> method with delattr().

Actually, you can -- but you need to delete it from
the class, not the instance:

 >>> delattr(X, 'f')
 >>> x.f()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'X' object has no attribute 'f'

-- 
Greg



More information about the Python-list mailing list