Using a class as a data container

前端 未结 12 1099
孤街浪徒
孤街浪徒 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:36

    Your way is better. Don't try to anticipate the future too much as you are not likely to succeed.

    However, it may make sense sometimes to use something like a C struct, for example if you want to identify different types rather than use dicts for everything.

提交回复
热议问题