classes vs dicts
Josiah Carlson
jcarlson at uci.edu
Thu May 13 11:22:54 EDT 2004
> Still, I think it is an overgeneralization to say that classes are
> just syntactic sugar for dictionaries.
How about this; classes are syntactic sugar for handling object
namespaces. Since object namespaces in Python are generally handled
with dictionaries, classes are therefore syntactic sugar for dictionaries.
Before I read the tutorial on classes when I was learning Python that
fateful afternoon years ago, I used dictionaries as the equivalent of
instance namespaces. For about 20 minutes it bothered me that I had to
use quotation marks to get and set attributes, until I read the class
portion of the tutorial and said "ah-hah, classes embed dictionaries as
namespaces, perfect", or something like that.
- Josiah
More information about the Python-list
mailing list