Skip to content

Commit df054b6

Browse files
authored
Merge pull request #79 from LEMS/test_file_close
To v0.6.7; improve file closure
2 parents 90b03be + c21fd06 commit df054b6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lems/model/model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def include_file(self, path, include_dirs=[]):
286286
parser = LEMSFileParser(self, inc_dirs, self.include_includes)
287287
if os.access(path, os.F_OK):
288288
if not path in self.included_files:
289-
parser.parse(open(path).read())
289+
with open(path) as f:
290+
parser.parse(f.read())
290291
self.included_files.append(path)
291292
return
292293
else:
@@ -298,7 +299,8 @@ def include_file(self, path, include_dirs=[]):
298299
new_path = inc_dir + "/" + path
299300
if os.access(new_path, os.F_OK):
300301
if not new_path in self.included_files:
301-
parser.parse(open(new_path).read())
302+
with open(new_path) as f:
303+
parser.parse(f.read())
302304
self.included_files.append(new_path)
303305
return
304306
else:
@@ -388,9 +390,11 @@ def export_to_file(self, filepath, level_prefix=" "):
388390
"\n",
389391
)
390392

391-
f = open(filepath, "w")
392-
f.write(xmlstr)
393-
f.close()
393+
with open(filepath, "w") as f:
394+
f.write(xmlstr)
395+
f.flush()
396+
os.fsync(f.fileno())
397+
394398

395399
def resolve(self) -> lems.model.Model:
396400
"""

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = PyLEMS
3-
version = 0.6.5
3+
version = 0.6.7
44
author = PyLEMS authors and contributors
55
66
maintainer_email = [email protected]

0 commit comments

Comments
 (0)