為 Sphinx 撰寫類別文件
sphinx 是把文件轉成 HTML 的好工具。這個練習中,你要為一個類別撰寫 docstring,讓 sphinx 可以加以利用。
請注意,你送出的 docstring 必須與參考解答「完全」一致。若你連續錯了好幾次,建議重整範例程式碼再重新開始。
本練習屬於課程
Python 的軟體工程原則
練習說明
- 在類別定義中,
fromtext_analyzer套件importDocument類別以供使用。 - 完成 docstring 中關於
__init__方法參數的那一行。 - 完成 docstring,填寫
SocialMedia類別的屬性(也就是「instance variables」)文件。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
____
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()