|
|
|
@ -7,15 +7,15 @@ class BookManager:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, data_file='books.json'):
|
|
|
|
def __init__(self, data_file='books.json'):
|
|
|
|
"""初始化图书管理器,加载已有图书数据"""
|
|
|
|
"""初始化图书管理器,加载已有图书数据"""
|
|
|
|
#self.data_file = data_file 111111111111111111122222222222
|
|
|
|
#self.data_file = data_file 2222222222
|
|
|
|
#self.books = self._load_books()
|
|
|
|
#self.books = self._load_books()
|
|
|
|
|
|
|
|
|
|
|
|
def _load_books(self):
|
|
|
|
def _load_books(self):
|
|
|
|
"""从文件加载图书数据"""
|
|
|
|
"""从文件加载图书数据"""
|
|
|
|
if os.path.exists(self.data_file):
|
|
|
|
if os.path.exists(self.data_file):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
with open(self.data_file, 'r', encoding='utf-8') as f:
|
|
|
|
#with open(self.data_file, 'r', encoding='utf-8') as f:
|
|
|
|
return json.load(f)
|
|
|
|
# return json.load(f)
|
|
|
|
except (json.JSONDecodeError, IOError) as e:
|
|
|
|
except (json.JSONDecodeError, IOError) as e:
|
|
|
|
print(f"加载图书数据失败: {e}")
|
|
|
|
print(f"加载图书数据失败: {e}")
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
|