classes vs dicts

John Roth newsgroups at jhrothjr.com
Thu May 6 12:06:53 EDT 2004


"Charlie" <charlvj at yahoo.com> wrote in message
news:be05f1d.0405060212.43929fe1 at posting.google.com...
> Greetings,
>
> I am pretty new to Python and like it very much, but there is one
> thing I can't figure out and I couldn't really find anything in the
> docs that addresses this.
>
> 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?
> I guess using dictionaries is fastest and easiest, but is this
> recommended?
>
> Thanx for any help.

As a number of people have said, there is no "right" answer.
My take on it is to ask how the rest of the program is organized.
If the rest of the program is object oriented, I'd use a class;
if it's procedurally oriented, I'd use a dictionary. In other words,
I'd try to keep some conceptual integrity with the program as
a whole.

John Roth





More information about the Python-list mailing list