Any problems with *lots* of attributes?

Aahz aahz at pythoncraft.com
Wed Feb 4 14:16:07 EST 2004


In article <246a4e07.0402040703.2be902a9 at posting.google.com>,
Frank Millman <frank at chagford.com> wrote:
>
>This is a question about the performance trade-off between two methods
>of storing data. One method is to create a separate attribute for each
>piece of data, and get/set the value according to its name. Another
>method is to create a list, and get/set the value according to its
>position in the list. In my limited tests, the first method is quicker.

That doesn't make any sense.  While lists and dicts are both essentially
O(1) for access, the constant is larger for dicts.  Please show us your
testing code.

OTOH, there's certainly nothing wrong with using dicts; they are the
single most fundamental Python data type after strings.  (All Python
name/attribute access is built on top of dicts.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death."  --GvR



More information about the Python-list mailing list