I was just reading post How can I assign a new class attribute via __dict__ in python? and there was one comment from @bruno desthuilliers saying:
One shouldn't directly call magic methods - they are here as implementation of operators or generic functions. In this case, the idiomatic solution is to use
setattr(obj, name, value)
.
The case of setattr seems out of scope of his own comment: not an operator, not really an implementation of generic function either.
Can someone explain the comment? Why should I prefer one over the other?
In which case is it preferable to use obj.__setattr__(name, value)
?