Sometimes it makes sense to cluster related data together. I tend to do so with a dict, e.g.,
self.group = dict(a=1, b=2, c=3)
print self.group['a']
One of my colleagues prefers to create a class
class groupClass(object):
def __init__(a, b, c):
self.a = a
self.b = b
self.c = c
self.group = groupClass(1, 2, 3)
print self.group.a
Note that we are not defining any class methods.
I like to use a dict because I like to minimize the number of lines of code. My colleague thinks the code is more readable if you use a class, and it makes it easier to add methods to the class in the future.
Which do you prefer and why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…