Objects versus dictionaries

Micah Carrick micah at greentackle.com
Sun Nov 14 20:00:18 CET 2010

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

# this is what I have now...
stuff = Stuff(foo="foo", bar="bar")
if stuff.is_valid():
  cust = Customer(name="John", email="foo at bar.com")
  order = Order(order_id=1234, amount=12.99)
  SomeObject.some_method(stuff, cust, order)

# this would also work...
stuff = Stuff(foo="foo", bar="bar")
if stuff.is_valid():
  cust = { 'name': "John", 'email': "foo at bar.com" }
  order = { 'order_id': 1234, 'amount': 12.99 }
  SomeObject.some_method(stuff, cust, order)

Micah Carrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101114/d80b38c2/attachment.html>

More information about the Python-list mailing list