I've a class say QClass
and an instance Q
of QClass
.
I've somehow created an attribute an_attribute
at run time in QClass
.
How do I delete that an_attribute
using del Q.an_attribute
?
I know that deleting that attribute from class will make it inaccessible from all of its instances.
Update: Q
is exposed to user and they can only go with del Q.an_attribute
. I can only change code of Q
or QClass
.
del
in python is more efficient than delattr
. See https://stackoverflow.com/a/1121068/4698026
So, go with
del type(Q).an_attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With