On Sat, Jan 23, 2016 at 04:25:01PM -0600, boB Stepp wrote:

> I think I now have this nuked out.  I am only just now realizing how
> powerful .__dict__ is:
[...]
>             self.__dict__[attribute_name] = attribute_value

Indeed, but generally speaking you hardly ever need to manually operate 
with a __dunder__ method or attribute. They're not quite private, but 
they are reserved, and normally you would use the public interface.

Instead of obj.__dict__[name], one should use one of the attribute 
functions:

getattr(obj, name)
setattr(obj, name, 999)
delattr(obj, name)

Instead of obj.__dict__, one should use vars(obj).

And of course, we never write obj.__len__() when we can write len(obj) 
instead. And so forth.



-- 
Steve
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to