Using a class as a data container

前端 未结 12 1097
孤街浪徒
孤街浪徒 2020-12-02 10:01

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\']
         


        
12条回答
  •  無奈伤痛
    2020-12-02 10:33

    I disagree that the code is more readable using a class with no methods. You usually expect functionality from a class, not only data.

    So, I'd go for a dict until the need for functionality arises, and then the constructor of the class could receive a dict :-)

提交回复
热议问题