-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathuser.py
42 lines (34 loc) · 926 Bytes
/
user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from PyInquirer import prompt
import csv
user_questions = [
{
"type": "input",
"name": "Name",
"message": "Name: ",
},
]
def export_user(infos):
with open('users.csv', 'a') as f: # You will need 'wb' mode in Python 2.x
w = csv.writer(f)
for key, value in infos.items():
w.writerow([value])
f.close()
def read_users():
with open('users.csv', 'r') as csv_file:
reader = csv.reader(csv_file)
L = []
for row in reader:
L.append(row[0])
csv_file.close()
return L
def add_user(name=""):
if name != "":
dict = {}
dict["Name"] = name
export_user(dict)
else:
infos = prompt(user_questions)
export_user(infos)
print("User Added !")
# This function should create a new user, asking for its name
return