Skip to content

Commit 1e56e62

Browse files
committed
worked on csv
1 parent 8388841 commit 1e56e62

File tree

6 files changed

+57
-52
lines changed

6 files changed

+57
-52
lines changed

code/justin/contacts.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name,phone,state,spirit animal
2-
Judson,5558675309,MS,mick jagger
2+
justin,5558675309,MS,tomato
33
Jane, 1115558798, CA, turtle
44
Mick, 8887775498, PA, woodpecker
5-
Sam, 9876543215, AR, hogger
5+
Sammy,31855963144, AR, hogger
66
Will,9876543216544,TY,Badger
77
bruce,8976541365,CA,dog

code/justin/files.py

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
p=1
99
new_entry = []
1010

11-
1211
while True:
1312
print('''\nWelcome to our contact database, please select from the following options:
1413
To create new user enter "create":
@@ -65,65 +64,46 @@
6564
fin.close()
6665
elif chg.lower() == 'phone':
6766
chg = input('Whats the new phone? ')
68-
lines[1] = chg
67+
data = data.replace(lines[1], chg)
68+
fin.close()
69+
fin = open('contacts.csv', 'wt')
70+
fin.write(data)
71+
fin.close()
6972
elif chg.lower() == 'state':
7073
chg = input('Whats the new state? ')
71-
lines[2] = chg
74+
data = data.replace(lines[2], chg)
75+
fin.close()
76+
fin = open('contacts.csv', 'wt')
77+
fin.write(data)
78+
fin.close()
7279
elif chg.lower() == 'spirit animal':
7380
chg = input('Whats the new spirit animal? ')
74-
lines[3] = chg
81+
data = data.replace(lines[3], chg)
82+
fin.close()
83+
fin = open('contacts.csv', 'wt')
84+
fin.write(data)
85+
fin.close()
7586
else:
7687
print('not a valid option')
7788
lines = (',').join(lines)
78-
79-
80-
81-
# data = data.replace()
82-
# for l in lines:
83-
# if n.lower() in l.lower():
84-
# print(f'Contact {l} found.')
85-
# spl = l.split(',')
86-
# upd = input('What needs updating, name, phone, state, spirit animal? ')
87-
# if upd.lower() == 'name'.lower():
88-
# spl[0]
89-
89+
elif a.lower() == 'delete':
90+
print('What contact do you want to delete? ')
91+
n = input('Enter name: ')
92+
fin = open('contacts.csv', 'rt')
93+
data = fin.read()
94+
if n.lower() in data.lower():
95+
print(f'User {n.title()} found')
96+
for num, lines in enumerate(data.split('\n')):
97+
print(num, lines)
98+
if n.lower() in lines.lower():
99+
lines = lines.split(',')
100+
# lines = ','.join(lines)
101+
print(lines)
102+
chg = input(f'Is this the entry you wish to delete?(y/n) ')
90103

91104

92-
# print(spl)
93-
# n = input('what name are we looking for: ')
94-
# if n.lower() in l[0].lower():
95-
# spl = l.split(',')
96-
# spl_a = spl.copy()
97-
# print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ')
98-
# a = input('Enter what to change: ')
99-
# if a.lower() == 'name':
100-
# nchg = input('What do you want to change the name to? ')
101-
# print(spl_a)
102-
103105

104-
# if a.lower() == 'name':
105-
106-
# n = input('enter a name: ')
107-
# new_entry.append(n)
108-
# ph = input('enter a phone number: ')
109-
# new_entry.append(ph)
110-
# st = input(f'enter {n}\'s state: ')
111-
# new_entry.append(st)
112-
# sa = input(f'enter {n}\'s spirit animal: ')
113-
# new_entry.append(sa)
114-
# j = ','.join(new_entry)
115-
# with open('contacts.csv', 'a') as file:
116-
# file.write(f'\n{j}')
117-
# with open('contacts.csv', 'a') as file:
118-
# new_entry = str(new_entry)
119-
# contacts.csv.write(new_entry)
120106

121-
# contacts=[]
122-
# keys=[]
123-
# ncontacts=[]
124-
# dic={}
125-
# p=1
126-
# new_entry = []
127107

128108
with open('contacts.csv', 'r') as file:
129109
lines = file.read().split('\n')
-28.8 KB
Binary file not shown.

code/justin/mcapstone/mycreate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
clock = pygame.time.Clock()
2727
pewpew = pygame.mixer.Sound('images/pew.wav')
2828

29-
tile_size = 100
3029

3130
bground_image = pygame.image.load('images/brk_bg.png')
3231
bg_logo = pygame.image.load('images/pdx_logo.png')

code/justin/test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
class Phonebook:
3+
def __init__(self, name, phone, state, spirit_animal):
4+
self.name = name
5+
self.phone = phone
6+
self.state = state
7+
self.spirt_animal = spirit_animal
8+
# contact_list = []
9+
# strings_list = ''
10+
# with open('contacts.csv', 'r') as file:
11+
# lines = file.read().split('\n')
12+
# for line in lines:
13+
# contact_list.append(line.split(','))
14+
# for contact in contact_list:
15+
# for variable in contact:
16+
17+
18+
j = Phonebook('John', 6016341458, 'MS', 'donkey')
19+
print(type(j.name))
20+

code/justin/tt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with open('contacts.csv', 'r') as file:
2+
lines = file.read().split('\n')
3+
for num, line in enumerate(lines):
4+
if num == 5:
5+
print(line)
6+
print(num, line)

0 commit comments

Comments
 (0)