为 Sphinx 编写类文档
sphinx 是一个非常适合将文档渲染为 HTML 的工具。在本练习中,您将为一个类编写 docstring,以便可被 sphinx 利用。
请注意,您的 docstring 必须与参考答案"完全一致"。如果多次提交仍不正确,建议重置示例代码并重新开始。
本练习是课程的一部分
Python 中的软件工程原理
练习说明
- 在类定义中,
import来自text_analyzer包的Document类。 - 完成 docstring 中关于
__init__方法参数的那一行。 - 通过补全
SocialMedia类的属性("实例变量")文档,完成整个 docstring。
交互式实操练习
通过完成这段示例代码来试试这个练习。
____
class SocialMedia(Document):
"""Analyze text data from social media
____ social media text to analyze
:____: Counter object containing counts of hashtags used in text
:____: Counter object containing counts of @mentions used in text
"""
def __init__(self, text):
Document.__init__(self, text)
self.hashtag_counts = self._count_hashtags()
self.mention_counts = self._count_mentions()