File tree Expand file tree Collapse file tree 5 files changed +17
-4
lines changed Expand file tree Collapse file tree 5 files changed +17
-4
lines changed Original file line number Diff line number Diff line change
1
+ * .data
Original file line number Diff line number Diff line change 1
- # Grocery shopping
1
+ # Grocery shopping[ WIP ]
2
2
3
3
You enter with items to be store in a ` .data ` file
4
4
Original file line number Diff line number Diff line change 1
1
import pickle
2
+ import grocery_list
2
3
3
4
file_name = "grocery-list.data"
4
5
@@ -15,6 +16,16 @@ def read():
15
16
return items
16
17
17
18
18
- def update (items ):
19
+ def update (item , new_item ):
20
+ items = read ()
21
+ items [items .index (item )] = new_item
19
22
with open (file_name , "r+b" ) as f :
20
23
pickle .dump (items , f )
24
+
25
+
26
+ def delete (item ):
27
+ items = read ()
28
+ items .remove (item )
29
+ with open (file_name , "r+b" ) as f :
30
+ items = grocery_list .get_list ()
31
+ pickle .dump (items , f )
Original file line number Diff line number Diff line change 4
4
5
5
def main ():
6
6
option = 0
7
+ items = grocery_list_repository .read ()
7
8
while True :
8
9
print ("1 - Add item to the list" )
9
10
print ("2 - Update item from the list" )
@@ -19,10 +20,10 @@ def main():
19
20
elif option == 2 :
20
21
item = input ("Enter the item you want to replace: " )
21
22
new_item = input ("Enter the new item to store on the list: " )
22
- grocery_list . alter (item , new_item )
23
+ grocery_list_repository . update (item , new_item )
23
24
elif option == 3 :
24
25
item = input ("Enter the item you want to remove: " )
25
- grocery_list . exclude (item )
26
+ grocery_list_repository . delete (item )
26
27
elif option == 4 :
27
28
print ("Items - " )
28
29
print (grocery_list_repository .read ())
You can’t perform that action at this time.
0 commit comments