パッケージ用のクラスを作成する
Python でクラスをどのように書くかを学んできました。 この演習では、パッケージ内でテキスト分析の基盤となる Document クラスの作成を始めます。 クラスを書いたら、ユーザーが簡単に利用できるように、パッケージの __init__.py を修正します。
作業するディレクトリ構造は次のとおりです。
working_dir
├── text_analyzer
│ ├── __init__.py
│ ├── counter_utils.py
│ ├── document.py
└── my_script.py
この演習はコースの一部です
Pythonで学ぶSoftware Engineeringの原則
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Define Document class
class Document:
"""A class for text analysis
:param text: string of text to be analyzed
:ivar text: string of text to be analyzed; set by `text` parameter
"""
# Method to create a new instance of Document
def ____(____, text):
# Store text parameter to the text attribute
____.text = text