在考虑设计时,在哪些情况下使用 class 与 dict 有意义?优点和缺点也会很有用。
例如,
class AlbumState:
""" AlbumState class, tracks photos shown, etc"""
def __init__ (self, album):
""" album for this object will track state"""
self.album = album
self.photos_shown = []
self.photos_notshown = range(album.size())
相对
albumstate['album'] = album
albumstate['photos_shown'] = []
albumstate['photos_notshown'] = range(album.size())