Use the "with" keyword when dealing with file objects
It is good practice to use the "with" keyword when dealing with file objects. This has the advantage that the file is properly closed after its suite finishes, even if an exception is raised on the way. It is also much shorter than writing equivalent try-finally blocks
This commit is contained in:
@@ -189,9 +189,8 @@ class AttackWPA(Attack):
|
||||
Color.pl("")
|
||||
# Check crack result
|
||||
if os.path.exists(key_file):
|
||||
f = open(key_file, "r")
|
||||
key = f.read().strip()
|
||||
f.close()
|
||||
with open(key_file, "r") as fid:
|
||||
key = fid.read().strip()
|
||||
os.remove(key_file)
|
||||
|
||||
Color.pl("{+} {G}Cracked WPA Handshake{W} PSK: {G}%s{W}\n" % key)
|
||||
|
||||
Reference in New Issue
Block a user