is attribute access a hash-lookup by name?

Greg Ewing see_reply_address at something.invalid
Wed Jul 3 00:53:28 EDT 2002


Steven Shaw wrote:

> As I understand it, in Python, an object is an associative array or
> hash. I imagine this means that every attribute access is a
> hash-lookup by name.


Yes.

> Does the implementation optimise this away
> somehow?


Currently, the only optimisation is that variable
names mentioned in code are interned, so their
hash function is only computed once, and they can
be compared for equality with a pointer comparison.


> Is there a way to have structs/records in Python where the members of
> the struct are looked up by offset (not by name)?


Yes -- use a list or tuple.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list