Fix ResourceWarning: unclosed file (#681)

Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:
Mickaël Schoentgen
2019-01-08 09:59:23 +01:00
committed by Libin Yang
parent 3dc50529ca
commit 2d70e9f747
10 changed files with 104 additions and 110 deletions

View File

@@ -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 )'))