classes vs dicts

Aahz aahz at pythoncraft.com
Thu May 6 12:33:44 EDT 2004


In article <m21xlxer6q.fsf at unique.phony.fqdn>,
Heather Coppersmith  <me at privacy.net> wrote:
>
>In the end (and in the implementation), classes are just syntactic
>sugar for dictionaries.
>
>    object.attribute    is equiv. to    dictionary[ 'key' ]

Saying that masks some critically important machinery that classes
provide.  For example::

    class A:
        x = 'spam'

    class B(A):
        pass

    z = B()
    print z.x
    print z.__dict__['x']

That machinery can make classes quite a bit slower in some cases, though
you're correct that it's more important to focus on the functional needs
than performance.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Adopt A Process -- stop killing all your children!



More information about the Python-list mailing list