📅  最后修改于: 2023-12-03 15:06:56.809000             🧑  作者: Mango
这个项目是针对图书店管理的一个简单的程序。它使用文件处理来存储所有书店的相关信息和更改。程序员可以通过命令行添加书籍、删除书籍、查找书籍、修改书籍信息、显示书库存信息等操作。
该程序具有以下功能:
def add_book():
book = {}
book['bookid'] = input('Enter book id: ')
book['title'] = input('Enter title: ')
book['author'] = input('Enter author: ')
book['publisher'] = input('Enter publisher: ')
book['price'] = input('Enter price: ')
books = load_books()
books.append(book)
with open('books.json', 'w') as f:
json.dump(books, f, indent=2)
print('Book added.')
def remove_book(search_key, value):
books = load_books()
for book in books:
if book[search_key] == value:
books.remove(book)
with open('books.json', 'w') as f:
json.dump(books, f, indent=2)
print('Book removed.')
def search_book(search_key, value):
books = load_books()
for book in books:
if book[search_key] == value:
print(book)
def update_book(search_key, value):
books = load_books()
for book in books:
if book[search_key] == value:
book['title'] = input('Enter title: ')
book['author'] = input('Enter author: ')
book['publisher'] = input('Enter publisher: ')
book['price'] = input('Enter price: ')
with open('books.json', 'w') as f:
json.dump(books, f, indent=2)
print('Book updated.')
def print_books():
books = load_books()
for book in books:
print(book)
以上代码仅供参考。更多细节和错误处理细节请参见完整代码实现。