Make reference models attribute private.

Create a get_model method to get a copy of reference data model.
This commit is contained in:
uggla 2015-07-10 14:27:20 +02:00
parent 925e4ced0a
commit da4f890e84
1 changed files with 10 additions and 1 deletions

View File

@ -23,7 +23,8 @@ class Model(object):
# Derive attribute name from file.
attr_name = os.path.basename(file)
attr_name = re.sub(r"\..*$", "", attr_name)
attr_name = "__" + attr_name # Make it private
# read json file
with open(file) as json_data:
data_structure = json.load(json_data)
@ -33,3 +34,11 @@ class Model(object):
setattr(self, attr_name, data_structure)
self.reference_items.append(attr_name)
return True
def get_model(self,model_name):
if not model_name[0:1] == "__":
model_name = "__" + model_name
model = getattr(self, model_name)
return model.copy()