Skip to content

Commit

Permalink
temporal: Use contextlib.nullcontext to not close sys.stdout in t.r…
Browse files Browse the repository at this point in the history
…ast.what
  • Loading branch information
echoix committed Dec 31, 2024
1 parent 7f07acf commit ecab2a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions temporal/t.rast.what/t.rast.what.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

import copy
import sys
from contextlib import nullcontext

import grass.script as gs

Expand Down Expand Up @@ -357,7 +358,7 @@ def one_point_per_row_output(
output is of type: x,y,start,end,value
"""
# open the output file for writing
with open(output, "w") if output != "-" else sys.stdout as out_file:
with open(output, "w") if output != "-" else nullcontext(sys.stdout) as out_file:
if write_header is True:
out_str = ""
if vcat:
Expand Down Expand Up @@ -439,7 +440,7 @@ def one_point_per_col_output(
# open the output file for writing

first = True
with open(output, "w") if output != "-" else sys.stdout as out_file:
with open(output, "w") if output != "-" else nullcontext(sys.stdout) as out_file:
for count in range(len(output_files)):
file_name = output_files[count]
gs.verbose(_("Transforming r.what output file %s") % (file_name))
Expand Down Expand Up @@ -566,7 +567,7 @@ def one_point_per_timerow_output(

first = False

with open(output, "w") if output != "-" else sys.stdout as out_file:
with open(output, "w") if output != "-" else nullcontext(sys.stdout) as out_file:
if write_header:
out_file.write(header + "\n")

Expand Down

0 comments on commit ecab2a0

Please sign in to comment.