Skip to content

Commit

Permalink
open file using context manager to properly close it again (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
tburandt authored Nov 21, 2024
1 parent 04c9e52 commit ef68a2a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ def path_to_string(path: Path) -> str:


def read_sense_from_problem_file(problem_fn: Path | str):
f = open(problem_fn).read()
if read_io_api_from_problem_file(problem_fn) == "lp":
with open(problem_fn) as file:
f = file.read()
file_format = read_io_api_from_problem_file(problem_fn)
if file_format == "lp":
return "min" if "min" in f.lower() else "max"
elif read_io_api_from_problem_file(problem_fn) == "mps":
elif file_format == "mps":
return "max" if "OBJSENSE\n MAX\n" in f else "min"
else:
msg = "Unsupported problem file format."
Expand Down

0 comments on commit ef68a2a

Please sign in to comment.