Python's Performance

Piet van Oostrum piet at
Tue Oct 11 14:37:08 CEST 2005

>>>>> Terry Hancock <hancock at> (TH) wrote:

>TH> He's got to be talking about runtime name-binding.  In
>TH> other words, when you refer to:

>TH> a.spam

>TH> the Python interpreter actually knows you labeled that attribute 'spam',
>TH> and the string is stored in a.__dict__ , so you can also access it as

>TH> getattr(a, 'spam')

>TH> etc.

>TH> I'm pretty sure this is what string "internment" is for, though, and
>TH> that such lookups are optimized out pretty much whenever possible.

In the case of getattr(a, 'spam') a string comparison for 'spam' has to be
done. AFAIK, in the case of a.spam the string 'spam' has been interned, so
that no string comparison is necessary at lookup, only a pointer
comparison. Due to hash collisions probably multiple comparisons could be
Piet van Oostrum <piet at>
URL: [PGP 8DAE142BE17999C4]
Private email: piet at

More information about the Python-list mailing list