Python dynamic attribute creation

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jul 2 04:41:03 EDT 2010


WANG Cong wrote:

> If you think setattr() is as ordinary as a trivial assignment, I will
> argue with you, this is personal taste.

To my way of thinking, getattr() and setattr() are the
fundamental way of accessing attributes in Python. The
dot notation is just syntactic sugar for the overwhelmingly
common case of a static attribute name.

So the dot-notation is more "ordinary" in the sense of
being more commonly used, but not in the sense of being
a simpler operation. Both are doing exactly the same
thing underneath.

-- 
Greg



More information about the Python-list mailing list