Skip to content

Commit

Permalink
grass.temporal.aggregation: Use a context manager for opening files (…
Browse files Browse the repository at this point in the history
…SIM115)
  • Loading branch information
echoix committed Aug 24, 2024
1 parent 7963689 commit a31c297
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions python/grass/temporal/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,11 @@ def aggregate_raster_maps(

# Create the r.series input file
filename = gs.tempfile(True)
file = open(filename, "w")
with open(filename, "w") as out_file:
for name in inputs:
string = "%s\n" % (name)
out_file.write(string)

for name in inputs:
string = "%s\n" % (name)
file.write(string)

file.close()
# Run r.series
try:
if len(inputs) > 1000:
Expand Down Expand Up @@ -365,11 +363,10 @@ def aggregate_by_topology(
if len(aggregation_list) > 1:
# Create the r.series input file
filename = gs.tempfile(True)
file = open(filename, "w")
for name in aggregation_list:
string = "%s\n" % (name)
file.write(string)
file.close()
with open(filename, "w") as out_file:
for name in aggregation_list:
string = "%s\n" % (name)
out_file.write(string)

mod = copy.deepcopy(r_series)
mod(file=filename, output=output_name)
Expand Down

0 comments on commit a31c297

Please sign in to comment.