Help with dynamic attributes.

Bruno Desthuilliers bdesth.quelquechose at
Mon Jan 9 13:31:42 EST 2006

Mr.Rech a écrit :
> My class's init method takes a list of lists as input argument and I'd
> like to create
> several attributes each one referencing one item of the passed list.
> Easy-of-use arguments
> has led me to call these attributes as x0, x1, x2 and so on. 

This is a very wrong design IM(ns)HO. A 'has-many' semantic is better 
expressed by a multivalued attribute (ie : list, tuple or dict) than by 
an undefined number of monovalued attributes. Also, the way you're 
trying to implement it, you will loose sync between individual 
monovalued attributes and the list of lists.

My 2 cents

More information about the Python-list mailing list