mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 20:10:08 +01:00
Fixes issue 1571:
Adding missing close for open. If the "close()" call is missing after a "open(filename)" call, the filename isn't guaranteed to be closed before the interpreter exits. This is generally a bad practice as explained here: https://stackoverflow.com/questions/7395542/is-explicitly-closing-files-important Also replaced "fid=open(filename) fid.close()" statements for files with the safer "with open(filename) as fid:" blocks. See https://www.python.org/dev/peps/pep-0343/
This commit is contained in:
@@ -130,13 +130,10 @@ def writeFile(filename, stub, values):
|
||||
if os.path.exists(filename):
|
||||
print("'%s' already exists. Exiting." % filename)
|
||||
sys.exit(1)
|
||||
output = open(filename, 'w')
|
||||
output.write(stub % values)
|
||||
output.close()
|
||||
with open(filename, 'w') as output:
|
||||
output.write(stub % values)
|
||||
print("Wrote %s" % filename)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -52,9 +52,9 @@ def writeFile(filename, stub, values):
|
||||
if os.path.exists(filename):
|
||||
print("'%s' already exists. Exiting." % filename)
|
||||
sys.exit(1)
|
||||
output = open(filename, 'w')
|
||||
output.write(stub % values)
|
||||
output.close()
|
||||
with open(filename, 'w') as output:
|
||||
output.write(stub % values)
|
||||
|
||||
print("Wrote %s" % filename)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ def main():
|
||||
for arg in sys.argv[1:]:
|
||||
for name in glob.glob(arg):
|
||||
m = hashlib.md5()
|
||||
m.update(open(name, 'rb').read())
|
||||
with open(name, 'rb') as fid:
|
||||
m.update(fid.read())
|
||||
print('%-45s %s' % (name, m.hexdigest()))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user