Use context manager instead of raw open

Raw open should be avoided to prevent that in case of an exception
the file is not closed.
This also has the advantage that if the user forgets to call close
the file is still closed.
This commit is contained in:
Xavier Bonaventura 2020-12-27 14:44:39 +01:00
parent 3cdab58d4e
commit 16402cca39

View File

@ -148,13 +148,11 @@ if __name__ == '__main__':
if len(options['core']): if len(options['core']):
for i in api[2].keys(): for i in api[2].keys():
f = open('%s/%s'%(options['core'], i), 'wb') with open('%s/%s'%(options['core'], i), 'wb') as f:
writeExtension(f, i, api[2][i], api[0], api[1]) writeExtension(f, i, api[2][i], api[0], api[1])
f.close()
if len(options['extensions']): if len(options['extensions']):
for i in api[3].keys(): for i in api[3].keys():
f = open('%s/%s'%(options['extensions'], i), 'wb') with open('%s/%s'%(options['extensions'], i), 'wb') as f:
writeExtension(f, i, api[3][i], api[0], api[1]) writeExtension(f, i, api[3][i], api[0], api[1])
f.close()