File tree 2 files changed +12
-12
lines changed
2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 1
1
# Author Steven Yeoh
2
2
# Copyright (c) 2019. All rights reserved.
3
3
4
- import os . path
4
+ import pathlib
5
5
6
6
7
7
def read_file ():
8
- if not os . path . exists ("./resources" ):
9
- os . mkdir ("./resources" )
8
+ if not pathlib . Path ("./resources" ). exists ( ):
9
+ pathlib . Path ("./resources" ). mkdir ( )
10
10
11
- if os . path . exists ("./resources/user_acc.txt" ):
11
+ if pathlib . Path ("./resources/user_acc.txt" ). exists ( ):
12
12
return open ("./resources/user_acc.txt" , "r" )
13
13
else :
14
14
return None
15
15
16
16
17
17
def save_new_user_to_file (username , password ):
18
- file = open ("./resources/user_acc.txt" , "a+" )
19
- file .write ("username={}:password={}\n " .format (username , password ))
18
+ with open ("./resources/user_acc.txt" , "a+" ) as file :
19
+ file .write ("username={}:password={}\n " .format (username , password ))
Original file line number Diff line number Diff line change @@ -32,10 +32,10 @@ def print_errors(errors):
32
32
33
33
34
34
def user_exists (username ):
35
- file = read_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
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
41
41
return False
You can’t perform that action at this time.
0 commit comments