classes vs dicts

Peter Maas peter.maas at mplusr.de
Thu May 6 06:29:59 EDT 2004


Charlie wrote:
> Say I want to write an address book program, what is the best way to
> define a person (and the like): create a class (as I would do in Java)
> or use a dictionary?

Use a class to model address data, advantage is that you can define
methods operating on address data, subclass address etc.

A dictionary gives you fast access to data by key. You could create
a dictionary of adresses that maps keys to addresses.

You can store such a dictionary with shelve module functions. Easy
to handle and sufficient if you don't need multi user access, an
SQL interface or have huge amount of data.

Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------



More information about the Python-list mailing list