パッケージ用クラスの作成
Pythonでのクラスの書き方について学びました。この演習では、パッケージでテキスト分析の基盤となる Document クラスをまず最初に作成していきます。クラスを書き終えたら、パッケージの __init__.py ファイルを編集して、ユーザーが簡単にアクセスできるようにしましょう。
作業するディレクトリの構造は以下のとおりです。
working_dir
├── text_analyzer
│ ├── __init__.py
│ ├── counter_utils.py
│ ├── document.py
└── my_script.py
この演習はコースの一部です
Python におけるソフトウェアエンジニアリングの原則
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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