|
44 | 44 | print(f'User {n} found: \n---------------------------------------------\n{l}')
|
45 | 45 | print('---------------------------------------------')
|
46 | 46 | elif a.lower() == 'update':
|
47 |
| - n = input('what name are we looking for: ') |
48 |
| - with open('contacts.csv', 'r') as file: |
49 |
| - lines = file.read().split('\n') |
50 |
| - for l in lines: |
51 |
| - spl = l.split(',') |
52 |
| - print(spl) |
53 |
| - if n.lower() in l.lower(): |
54 |
| - spl = l.split(',') |
55 |
| - spl_a = spl.copy() |
56 |
| - print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ') |
57 |
| - a = input('Enter what to change: ') |
58 |
| - if a.lower() == 'name': |
59 |
| - |
60 |
| - |
61 |
| - # if a.lower() == 'name': |
62 |
| - |
| 47 | + print('What contact do you want to update? ') |
| 48 | + n = input('Enter name: ') |
| 49 | + fin = open('contacts.csv', 'rt') |
| 50 | + data = fin.read() |
| 51 | + if n.lower() in data.lower(): |
| 52 | + print(f'User {n.title()} found') |
| 53 | + for lines in data.split('\n'): |
| 54 | + if n.lower() in lines.lower(): |
| 55 | + lines = lines.split(',') |
| 56 | + # lines = ','.join(lines) |
| 57 | + print(lines) |
| 58 | + chg = input(f'What needs to change, name, phone, state or spirit animal? ') |
| 59 | + if chg.lower() == 'name': |
| 60 | + chg = input('Whats the new name? ') |
| 61 | + data.replace(lines[0],chg) |
| 62 | + lines[0] = chg |
| 63 | + elif chg.lower() == 'phone': |
| 64 | + chg = input('Whats the new phone? ') |
| 65 | + lines[1] = chg |
| 66 | + elif chg.lower() == 'state': |
| 67 | + chg = input('Whats the new state? ') |
| 68 | + lines[2] = chg |
| 69 | + elif chg.lower() == 'spirit animal': |
| 70 | + chg = input('Whats the new spirit animal? ') |
| 71 | + lines[3] = chg |
| 72 | + else: |
| 73 | + print('not a valid option') |
| 74 | + lines = (',').join(lines) |
| 75 | + |
63 | 76 |
|
64 | 77 |
|
| 78 | + # data = data.replace() |
| 79 | + # for l in lines: |
| 80 | + # if n.lower() in l.lower(): |
| 81 | + # print(f'Contact {l} found.') |
| 82 | + # spl = l.split(',') |
| 83 | + # upd = input('What needs updating, name, phone, state, spirit animal? ') |
| 84 | + # if upd.lower() == 'name'.lower(): |
| 85 | + # spl[0] |
| 86 | + |
65 | 87 |
|
66 |
| - |
67 |
| - |
68 | 88 |
|
69 |
| - |
| 89 | +# print(spl) |
| 90 | + # n = input('what name are we looking for: ') |
| 91 | + # if n.lower() in l[0].lower(): |
| 92 | + # spl = l.split(',') |
| 93 | + # spl_a = spl.copy() |
| 94 | + # print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ') |
| 95 | + # a = input('Enter what to change: ') |
| 96 | + # if a.lower() == 'name': |
| 97 | + # nchg = input('What do you want to change the name to? ') |
| 98 | + # print(spl_a) |
| 99 | + |
70 | 100 |
|
| 101 | + # if a.lower() == 'name': |
| 102 | + |
71 | 103 | # n = input('enter a name: ')
|
72 | 104 | # new_entry.append(n)
|
73 | 105 | # ph = input('enter a phone number: ')
|
|
78 | 110 | # new_entry.append(sa)
|
79 | 111 | # j = ','.join(new_entry)
|
80 | 112 | # with open('contacts.csv', 'a') as file:
|
81 |
| -# file.write(f'\n{j}') |
82 |
| - |
83 |
| - |
84 |
| - |
| 113 | +# file.write(f'\n{j}') |
85 | 114 | # with open('contacts.csv', 'a') as file:
|
86 | 115 | # new_entry = str(new_entry)
|
87 | 116 | # contacts.csv.write(new_entry)
|
88 | 117 |
|
| 118 | +# contacts=[] |
| 119 | +# keys=[] |
| 120 | +# ncontacts=[] |
| 121 | +# dic={} |
| 122 | +# p=1 |
| 123 | +# new_entry = [] |
| 124 | + |
89 | 125 | with open('contacts.csv', 'r') as file:
|
90 | 126 | lines = file.read().split('\n')
|
91 | 127 | for l in lines:
|
92 |
| - contacts.append(l.split(',')) |
93 |
| - for c in contacts[0]: |
94 |
| - keys.append(c) |
| 128 | + contacts.append(l.split(',')) #makes lists of contacts seperated by , inside of the contacts list |
| 129 | + for c in contacts[0]: #header value for key: |
| 130 | + keys.append(c) #puts the header value into a list by itself called keys |
95 | 131 | # contacts.append(new_entry)
|
96 | 132 | while p < len(contacts):
|
97 | 133 | a = dic.copy()
|
|
0 commit comments