[Tutor] Benefit/Disadvantage to storing data as dictionary vs. in a class

Adam amgaweda at gmail.com
Fri Jun 1 15:12:08 CEST 2012


I'm working on a class that handles multiple rooms that generate a large 
amount of data. Currently my class model looks something like this (more 
apologies for any indentation errors):
Class Model:
     rooms= {}
     for z in range(num_of_zones):
         for i in range(24):
             tmp[i] = { VAR:0, SD:0, AVG:0, READINGS:[] }
             tmp[i]['updated'] = datetime.utcnow()
                 for j in OT_RANGE:
                     tmp[i][j] = { VAR:0, SD:0, AVG:0, READINGS:[] }
         rooms[z] = tmp

In case that gets complicated, I'm looking to store readings based off 
the current hour and current outside temperature. The Model class has 
other variables and functions that it uses to compare and manipulate the 
data as it comes in.

My question is in regards to the storing all this data in a dictionary, 
which makes it easy to reference self.rooms[z][12][85][AVG]; however is 
this better/worse or the same as creating a 'Room' class to store the 
data? Since a 'Room' only contains a large amount of data, but doesn't 
contain any functions, which form of storing the data is considered 
'better'?

Thank you,
Adam


More information about the Tutor mailing list