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:
@@ -45,9 +45,8 @@ class Wifite(object):
|
||||
if not os.path.exists(name):
|
||||
Color.pl('{!} {O}file {C}%s{O} not found{W}' % name)
|
||||
return
|
||||
f = open(name, 'r')
|
||||
json = loads(f.read())
|
||||
f.close()
|
||||
with open(name, 'r') as fid:
|
||||
json = loads(fid.read())
|
||||
for (index, item) in enumerate(json):
|
||||
Color.pl('\n{+} Cracked target #%d:' % (index + 1))
|
||||
cr = CrackResult.load(item)
|
||||
|
||||
Reference in New Issue
Block a user