Objects versus dictionaries

Hidura hidura at gmail.com
Sun Nov 14 20:34:40 CET 2010


Use *kargs to pass all the informatio that you need if u want in the
future extended this will be usefull

2010/11/14, Micah Carrick <micah at greentackle.com>:
> 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?
>
> # 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
>

-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.



More information about the Python-list mailing list