write_model(model, model_path, backup=True, log_input=False, version=None)[source]#

Write model to files.

Write model to text files in a folder(directory) tree at model_path.

Model attributes, such as its name and refs, are output in the file named, 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.

For spaces and cells created by new_space_from_excel() and new_cells_from_excel(), the source Excel files are copied into the same directory where the text files for the spaces the methods are associated with are located. Then when the model is read by read_model() function, the methods are invoked to create the spaces or cells.

Method write() performs the same operation.

Changed in version 0.8.0: log_input parameter is added.

Changed in version 0.1.0: version parameter is added.

New in version 0.0.22.


The order of members of each type (Space, Cells, Ref) is not preserved by write_model() and read_model().

  • 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 under model_path. Defaults to False.

  • version (int, optional) – Format version to write model. Defaults to the most recent version.