-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbook.py
More file actions
31 lines (24 loc) · 757 Bytes
/
Copy pathbook.py
File metadata and controls
31 lines (24 loc) · 757 Bytes
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
import json
class Book:
def __init__(self):
self.books = []
def add_book(self, title, author):
new_book = {}
new_book["Title"] = title
new_book["Author"] = author
self.books.append(new_book)
print("Book: {0}".format(new_book))
return json.dumps(new_book)
def del_book(self, title):
found = False
for idx, book in enumerate(self.books):
if book["Title"] == title:
index = idx
found = True
del self.books[idx]
print("books: {0}".format(json.dumps(self.books)))
return found
def get_all_books(self):
return self.books
def json_list(self):
return json.dumps(self.books)