mgear-dev / mgear4

mGear v.4.x.x (python 3 ready) https://mgear4.readthedocs.io
MIT License
266 stars 94 forks source link

Use with statement for file writing #162

Closed chris-lesage closed 1 year ago

chris-lesage commented 1 year ago

In https://github.com/mgear-dev/mgear4/blob/master/release/scripts/mgear/shifter/__init__.py

In the method data_collector_output()

f = open(file_path, "w")
f.write(json.dumps(self.build_data, indent=4))
f.close()
file_path = None

Should be rewritten as the safer and recommended with statement:

with open(file_path, 'w') as f:
    f.write(json.dumps(self.build_data, indent=4))
file_path = None
miquelcampos commented 1 year ago

Thanks @chris-lesage I will review this