|
33 | 33 | """ |
34 | 34 |
|
35 | 35 | import ast |
36 | | -import csv |
37 | 36 | from dataclasses import dataclass |
38 | 37 | import logging |
39 | 38 | import numbers |
@@ -979,16 +978,17 @@ def simulate_cmd( |
979 | 978 | if simargs: |
980 | 979 | om_cmd.args_set(args=simargs) |
981 | 980 |
|
982 | | - overrideFile = self.getWorkDirectory() / f"{self._model_name}_override.txt" |
983 | 981 | if self._override_variables or self._simulate_options_override: |
984 | | - tmpdict = self._override_variables.copy() |
985 | | - tmpdict.update(self._simulate_options_override) |
986 | | - # write to override file |
987 | | - with open(file=overrideFile, mode="w", encoding="utf-8") as fh: |
988 | | - for key, value in tmpdict.items(): |
989 | | - fh.write(f"{key}={value}\n") |
| 982 | + override_file = self.getWorkDirectory() / f"{self._model_name}_override.txt" |
990 | 983 |
|
991 | | - om_cmd.arg_set(key="overrideFile", val=overrideFile.as_posix()) |
| 984 | + override_content = ( |
| 985 | + "\n".join([f"{key}={value}" for key, value in self._override_variables.items()]) |
| 986 | + + "\n".join([f"{key}={value}" for key, value in self._simulate_options_override.items()]) |
| 987 | + + "\n" |
| 988 | + ) |
| 989 | + |
| 990 | + override_file.write_text(override_content) |
| 991 | + om_cmd.arg_set(key="overrideFile", val=override_file.as_posix()) |
992 | 992 |
|
993 | 993 | if self._has_inputs: # if model has input quantities |
994 | 994 | # csvfile is based on name used for result file |
@@ -1348,9 +1348,10 @@ def _createCSVData(self, csvfile: Optional[pathlib.Path] = None) -> pathlib.Path |
1348 | 1348 | if csvfile is None: |
1349 | 1349 | csvfile = self.getWorkDirectory() / f'{self._model_name}.csv' |
1350 | 1350 |
|
1351 | | - with open(file=csvfile, mode="w", encoding="utf-8", newline="") as fh: |
1352 | | - writer = csv.writer(fh) |
1353 | | - writer.writerows(csv_rows) |
| 1351 | + # basic definition of a CSV file using csv_rows as input |
| 1352 | + csv_content = "\n".join([",".join(map(str, row)) for row in csv_rows]) + "\n" |
| 1353 | + |
| 1354 | + csvfile.write_text(csv_content) |
1354 | 1355 |
|
1355 | 1356 | return csvfile |
1356 | 1357 |
|
|
0 commit comments