我有一个图书馆,我想在其中创建一本新书,然后将其添加到我的书单中。我遇到的问题是在调用之间保存文件。
这就是我读取文件的方式:
def read_bookfile():
try:
booklibrary_file = open("a.txt")
booklibrary_list = []
booklist = booklibrary_file.readlines()
for rad in booklist:
linelist = rad.split("/")
title = linelist[0]
firstname = linelist[1]
lastname = linelist[2]
isbn = int(linelist[3])
availability = linelist[4]
borrowed = linelist[5]
late = linelist[6]
returnday = linelist[7]
b = Book(title, firstname, lastname, isbn, availability, borrowed, late, returnday)
booklibrary_list.append(b)
booklibrary_file.close()
return booklibrary_list
现在我想知道如何保存到我的文件中。