mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Utilize Python context managers for opening/closing files
In some of these cases, files were not being closed
This commit is contained in:
parent
7c45ff8e05
commit
2ab43bea5d
5 changed files with 18 additions and 21 deletions
|
@ -41,18 +41,16 @@ def replaceFileIfChanged(filename, newContents):
|
|||
|
||||
# oldFileContents = ""
|
||||
# try:
|
||||
# oldFile = open(filename, 'rb')
|
||||
# oldFileContents = ''.join(oldFile.readlines())
|
||||
# oldFile.close()
|
||||
# with open(filename, 'rb') as oldFile:
|
||||
# oldFileContents = ''.join(oldFile.readlines())
|
||||
# except:
|
||||
# pass
|
||||
|
||||
# if newContents == oldFileContents:
|
||||
# return False
|
||||
|
||||
f = open(filename, 'wb')
|
||||
f.write(newContents)
|
||||
f.close()
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(newContents)
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue