Skip to content

Commit

Permalink
Ensure output file is closed
Browse files Browse the repository at this point in the history
From #2

Wraps the file handling in a context manager that automatically closes
the file (see https://stackoverflow.com/questions/21275836/)
  • Loading branch information
4iar committed Aug 10, 2021
1 parent 9846d56 commit ae52495
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions write.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def parse_args(raw_args):

def write_to_file(filename, command, output):
"""Write the output to the given file, headed by the command"""
f = open(filename, 'w')

f.write("(lldb) " + command + '\n\n')
f.write(output)
with open(filename, 'w') as f:
f.write("(lldb) " + command + '\n\n')
f.write(output)


def handle_call(debugger, raw_args, result, internal_dict):
Expand Down

0 comments on commit ae52495

Please sign in to comment.