[Python >= 3.9] パッケージ内のファイルにアクセスする

※zipファイル化されているモジュール/パッケージでも使用可能
※importlib.resources.filesを使わないアクセス方法は3.11で非推奨になる。

関連
 [Python >= 3.9] パッケージ内のファイルにアクセスする その2

参考資料
 importlib.resources -- Package resource reading, opening and access
 https://docs.python.org/ja/3/library/importlib.resources.html

 Using importlib_resources
 https://importlib-resources.readthedocs.io/en/latest/using.html

■ディレクトリ構造
※名前空間パッケージで利用できる(__init__.pyは必要ない)
test
  __main__.py
  resource/
    csv/
      sample01.csv
    html/
      template/
        sample02.html
■サンプルコード
import importlib.resources


## CSVファイルの読み込み
import resource.csv
CSV_ROOT_PATH = importlib.resources.files(resource.csv)

data = CSV_ROOT_PATH.joinpath("sample01.csv").\
    read_text(encoding='utf-8')
print(f"** csv data\n{data}")


## HTMLファイルの読み込み
#  import resource.htmlとしてimportし、後でtemplateを追加することも可
import resource.html
HTML_ROOT_PATH = importlib.resources.files(resource.html)

data = HTML_ROOT_PATH.joinpath("template", "sample02.html").\
    read_text(encoding='utf-8')
print(f"** html data\n{data}")