Skip to content

Commit 10f947b

Browse files
committed
[ModelicaSystem*] fix pylint error - open()
* use open() with encoding & use fh for filehandle
1 parent a114c7a commit 10f947b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ def run(self) -> int:
238238
if not path_bat.exists():
239239
raise ModelicaSystemError("Batch file (*.bat) does not exist " + str(path_bat))
240240

241-
with open(path_bat, 'r') as file:
242-
for line in file:
241+
with open(file=path_bat, mode='r', encoding='utf-8') as fh:
242+
for line in fh:
243243
match = re.match(r"^SET PATH=([^%]*)", line, re.IGNORECASE)
244244
if match:
245245
path_dll = match.group(1).strip(';') # Remove any trailing semicolons
@@ -850,9 +850,9 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
850850
tmpdict = self.overridevariables.copy()
851851
tmpdict.update(self.simoptionsoverride)
852852
# write to override file
853-
with open(overrideFile, "w") as file:
853+
with open(file=overrideFile, mode="w", encoding="utf-8") as fh:
854854
for key, value in tmpdict.items():
855-
file.write(f"{key}={value}\n")
855+
fh.write(f"{key}={value}\n")
856856

857857
om_cmd.arg_set(key="overrideFile", val=overrideFile.as_posix())
858858

@@ -1131,8 +1131,8 @@ def createCSVData(self) -> pathlib.Path:
11311131

11321132
csvFile = self.tempdir / f'{self.modelName}.csv'
11331133

1134-
with open(csvFile, "w", newline="") as f:
1135-
writer = csv.writer(f)
1134+
with open(file=csvFile, mode="w", encoding="utf-8", newline="") as fh:
1135+
writer = csv.writer(fh)
11361136
writer.writerows(csv_rows)
11371137

11381138
return csvFile
@@ -1233,11 +1233,11 @@ def load_module_from_path(module_name, file_path):
12331233

12341234
overrideLinearFile = self.tempdir / f'{self.modelName}_override_linear.txt'
12351235

1236-
with open(overrideLinearFile, "w") as file:
1236+
with open(file=overrideLinearFile, mode="w", encoding="utf-8") as fh:
12371237
for key, value in self.overridevariables.items():
1238-
file.write(f"{key}={value}\n")
1238+
fh.write(f"{key}={value}\n")
12391239
for key, value in self.linearOptions.items():
1240-
file.write(f"{key}={value}\n")
1240+
fh.write(f"{key}={value}\n")
12411241

12421242
om_cmd.arg_set(key="overrideFile", val=overrideLinearFile.as_posix())
12431243

0 commit comments

Comments
 (0)