当前位置: 首页>>代码示例>>Python>>正文


Python Book.book_by_record方法代码示例

本文整理汇总了Python中book.Book.book_by_record方法的典型用法代码示例。如果您正苦于以下问题:Python Book.book_by_record方法的具体用法?Python Book.book_by_record怎么用?Python Book.book_by_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在book.Book的用法示例。


在下文中一共展示了Book.book_by_record方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_record

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import book_by_record [as 别名]
 def add_record(self, book):
     """
         Adds a new record of a book to the file.If there is a book record
         with the same title,author and year of publication then the book
         is recorded and we only change the number of copies of the
         recorded book.Otherwise, we add the new book.
     """
     with open(self.file, 'r') as file:
         data = file.readlines()
     try:
         _file = self.file
         enum = enumerate(data)
         I = next(i for i, v in enum if Book.book_by_record(v) == book)
         os.rename(os.path.realpath(_file), os.path.realpath(_file)+".bak")
         copies = int(data[I].rstrip('\n').split('+')[-1])
         book_update = book.special_record().rstrip('\n').split('+')
         book_update[-1] = str(int(book_update[-1]) + copies)
         data[I] = '+'.join(book_update) + '\n'
         with open(_file, 'w') as file:
             file.writelines(data)
         os.remove(os.path.realpath(self.file)+".bak")
     except StopIteration:
         data.append(book.special_record())
         with open(self.file, 'a') as file:
             file.write(book.special_record())
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:27,代码来源:book_database.py

示例2: test_book_by_record

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import book_by_record [as 别名]
 def test_book_by_record(self):
     book = Book.book_by_record("Fall+Carl Jon+1999+Crime+3+2")
     self.assertEqual(
         "<Book Information>\nTitle:Fall\nAuthor:Carl "
         + "Jon\nPublished in:1999\nGenre:Crime\n"
         + "Rating:3.0\nNumber of copies:2\n",
         str(book),
     )
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:10,代码来源:book_tests.py

示例3: booklist

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import book_by_record [as 别名]
 def booklist(self):
     """
         Returns a list of the books that are recorded in the file.
     """
     with open(self.file, 'r') as file:
         return [Book.book_by_record(book) for book in file.readlines()]
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:8,代码来源:book_database.py


注:本文中的book.Book.book_by_record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。