What the normal style for data objects in python. Lets say I have a method that gets a customer from somewhere (net, DB, ....) what type of object should I return. I see several choices:
- a tuple
- a dictionary
- a class instance (are data classes 'normal')
I am sure there are others. Doing my first big python project and so would like to start out using best practices for the start
Wow - surprised at the negative reaction to the question. Maybe not being clear
I Have lots of different data items i want to pass around my code. User, product, customer, order,... (in fact they are nothing like that but the its simpler with obvious types of thing). so I have
def get_user():
return x
what should x be. an instance of class called user, a dict, a tuple...
there are no methods associated with the objects, pure data
seems like namedtuples are the way to go
edit: How about this as a style
class product:
pass
...
def get_product():
... db read stuff
pr = product()
pr.name = dbthing[0]
pr.price = dbthing[1]
return pr
Is that barf inducing or well established style or odd or what? It works. From the consumer side it makes for readable code
def xxx():
pr = get_product()
total = amount * pr.price