本文整理汇总了Python中book.Book.add_section方法的典型用法代码示例。如果您正苦于以下问题:Python Book.add_section方法的具体用法?Python Book.add_section怎么用?Python Book.add_section使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类book.Book
的用法示例。
在下文中一共展示了Book.add_section方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import add_section [as 别名]
class Tractatus:
# This is the book
tractatus = None
def __init__(self):
""" Construct the Tractatus """
# Build the Book object
self.tractatus = Book()
# Get the tractatus from text
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
all_text = open(os.path.join(SITE_ROOT, "static", "tractatus.txt"), 'r')
output = all_text.readlines()
# Read the file line by line into self.tractatus
# The actual content only begins at line 30 until the end
for i in range(30, len(output)):
complete_string = str(output[i])
# We need to separate the index and the text
split_string = complete_string.partition(" ")
index = split_string[0]
text = split_string[2].rstrip("\n")
# Load them in
self.tractatus.add_section(index, text)
# print self.tractatus
def get_book(self):
return self.tractatus