[portland] Seeking opinions on choosing data types: dictionary or instance attributes?

ray at bme.ogi.edu ray at bme.ogi.edu
Tue Nov 27 21:23:05 CET 2007


I'm new to python and the Portland users group and all.  Correct me if
I'm offtopic or out of line or anything...

I'm wondering if you experienced coders have any advice on choosing
data types in Python.  We're writing a program with a large data
structure and I'm wondering when we should use instance attributes vs.
when we should use dictionaries. (We'll have some lists when sequence
matters)  My friend loves dictionaries and says to make every class
a dictionary; then instead of any instance attributes, have key value pairs.

To me, struct['substruct']['mywidget']['color'] seems more awkward than
struct.substruct.mywidget.color but he points out that with
dictionaries it's easier to implement code where you ask the user,
"What do you want to know about your widget?" and then return
struct[2]['substruct']['mywidget']['userRequest'].    I don't know yet
if we'll ask any such questions.  If the class "Widget" only has two
attributes, 'color' and 'make' I'm inclined to make them instance
attributes.  But I really don't know...

Any advice or guidelines?  Are there any disadvantages to using all  
these dictionaries?

Thank you,
Raychel




More information about the Portland mailing list