Skip to content

Commit 1f3574d

Browse files
committed
fix file close
1 parent 68721db commit 1f3574d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

exercises/utils/validate_util.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def validate_user_credentials(username, password):
2222
file = read_file()
2323
for data in file:
2424
if data.split(":")[0].split("=")[1] == username and data.split(":")[1].split("=")[1].rstrip("\n") == password:
25+
file.close()
2526
return True
27+
file.close()
2628
return False
2729

2830

@@ -32,10 +34,12 @@ def print_errors(errors):
3234

3335

3436
def user_exists(username):
35-
with read_file() as file:
36-
if file is not None:
37-
for data in file:
38-
if data.split(":")[0].split("=")[1] == username:
39-
return True
40-
return False
37+
file = read_file()
38+
if file is not None:
39+
for data in file:
40+
if data.split(":")[0].split("=")[1] == username:
41+
file.close()
42+
return True
43+
file.close()
44+
return False
4145
return False

0 commit comments

Comments
 (0)