modelx.write_model#
- write_model(model, model_path, backup=True, log_input=False, version=None)[source]#
Write model to files.
Write
modelto text files in a folder(directory) tree atmodel_path.Model attributes, such as its name and refs, are output in the file named _model.py, directly under model_path. For each space in the model, a text file is created with the same name as the space with “.py” extension. The tree structure of the spaces is represented by the tree of folders, i.e. child spaces of a space is stored in a folder named the space.
Generated text files are Python pseudo-scripts, i.e. they are syntactically correct but semantically not-correct Python scripts, that can only be interpreted through
read_model()function.Dynamic spaces and cells values are not stored.
Spaces and cells created by
new_space_from_excel()andnew_cells_from_excel()are written out in the same way as other spaces and cells: their definitions are output to the text files, and the values read from the source Excel files are saved as input values in data files under _data folders. The source Excel files themselves are not copied, and they are not needed when the model is read back byread_model()function, which restores the spaces and cells from the saved data without invoking the methods again.Method
write()performs the same operation.Warning
The order of members of each type (Space, Cells, Ref) is not preserved by
write_model()andread_model().- Parameters:
model – Model object to write.
model_path (str) – Folder path where the model will be output.
backup (bool, optional) – Whether to backup the directory/folder if it already exists. Defaults to
True.log_input (bool, optional) – If
True, input values in Cells are output to _input_log.txt undermodel_path. Defaults toFalse.version (int, optional) – Format version to write model. Defaults to the most recent version.
Changed in version 0.22.0: The source Excel files for spaces and cells created by
new_space_from_excel()andnew_cells_from_excel()are no longer copied into the output folder tree. Instead, the values read from the files are saved as input values.Changed in version 0.8.0:
log_inputparameter is added.Changed in version 0.1.0:
versionparameter is added.Added in version 0.0.22.