Objects versus dictionaries

Dan Stromberg drsalists at gmail.com
Mon Nov 15 00:08:18 CET 2010

On Sun, Nov 14, 2010 at 11:20 AM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick <micah at greentackle.com>
> wrote:
> > I'm writing a little API that other people will use. There are up to 3
> > "objects" that get passed around. One of them has some validation
> methods,
> > the other two simply store data and probably won't have any validation or
> > other methods. I only made them objects so that they are syntactically
> (is
> > that a word?) similar the other object rather than using dictionaries. I
> > figure it also better allows for changes in the future.
> >
> > Any thoughts on the pros/cons of using my own objects over a dictionary
> > objects?
> Objects are definitely nicer to work with syntactically, and they help
> make your program's types more explicit.
> Rather than coding the "data holder" classes manually, consider using
> namedtuples instead:
> http://docs.python.org/library/collections.html#collections.namedtuple

namedtuples are nice, but I don't think pylint understands how to look
inside them as well as it understands how to look inside class instances.

pylint isn't for everyone, but I find it very useful in producing sturdy
python code with few surprises at runtime.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101114/9b72c6e5/attachment.html>

More information about the Python-list mailing list