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:
@@ -39,10 +39,8 @@ class Aircrack(object):
|
||||
def get_key_hex_ascii(self):
|
||||
if not self.is_cracked():
|
||||
raise Exception('Cracked file not found')
|
||||
f = open(self.cracked_file, 'r')
|
||||
hex_raw = f.read()
|
||||
f.close()
|
||||
|
||||
with open(self.cracked_file, 'r') as fid:
|
||||
hex_raw = fid.read()
|
||||
hex_key = ''
|
||||
ascii_key = ''
|
||||
while len(hex_raw) > 0:
|
||||
|
||||
Reference in New Issue
Block a user