Skip to content

Commit 38a10ee

Browse files
committed
worked on lab
1 parent 6781c0e commit 38a10ee

File tree

2 files changed

+64
-29
lines changed

2 files changed

+64
-29
lines changed

code/justin/contacts.csv

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ Justin,5558675309,MS,mick jagger
33
Jane, 1115558798, CA, turtle
44
Mick, 8887775498, PA, woodpecker
55
Sam, 9876543215, AR, hogger
6-
Happy,Gilmore,VA,croc
7-
Chad,highschool,HS,Bunny
8-
dingus,berry,mi,berry
6+
Will,9876543216544,TY,Badger
7+
bruce,8976541365,CA,dog

code/justin/files.py

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,62 @@
4444
print(f'User {n} found: \n---------------------------------------------\n{l}')
4545
print('---------------------------------------------')
4646
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+
6376

6477

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+
6587

66-
67-
6888

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+
70100

101+
# if a.lower() == 'name':
102+
71103
# n = input('enter a name: ')
72104
# new_entry.append(n)
73105
# ph = input('enter a phone number: ')
@@ -78,20 +110,24 @@
78110
# new_entry.append(sa)
79111
# j = ','.join(new_entry)
80112
# with open('contacts.csv', 'a') as file:
81-
# file.write(f'\n{j}')
82-
83-
84-
113+
# file.write(f'\n{j}')
85114
# with open('contacts.csv', 'a') as file:
86115
# new_entry = str(new_entry)
87116
# contacts.csv.write(new_entry)
88117

118+
# contacts=[]
119+
# keys=[]
120+
# ncontacts=[]
121+
# dic={}
122+
# p=1
123+
# new_entry = []
124+
89125
with open('contacts.csv', 'r') as file:
90126
lines = file.read().split('\n')
91127
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
95131
# contacts.append(new_entry)
96132
while p < len(contacts):
97133
a = dic.copy()

0 commit comments

Comments
 (0)