Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:
committed by
Libin Yang
parent
3dc50529ca
commit
2d70e9f747
@@ -19,15 +19,16 @@ def main():
|
||||
|
||||
startTime = time.time()
|
||||
if mode.lower().startswith('e'):
|
||||
content = open(inputFile).read()
|
||||
with open(inputFile) as f:
|
||||
content = f.read()
|
||||
translated = transCipher.encryptMessage(key, content)
|
||||
elif mode.lower().startswith('d'):
|
||||
content = open(outputFile).read()
|
||||
with open(outputFile) as f:
|
||||
content = f.read()
|
||||
translated =transCipher .decryptMessage(key, content)
|
||||
|
||||
outputObj = open(outputFile, 'w')
|
||||
outputObj.write(translated)
|
||||
outputObj.close()
|
||||
with open(outputFile, 'w') as outputObj:
|
||||
outputObj.write(translated)
|
||||
|
||||
totalTime = round(time.time() - startTime, 2)
|
||||
print(('Done (', totalTime, 'seconds )'))
|
||||
|
||||
Reference in New Issue
Block a user