3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonのmoduleとpackageがごっちゃになるの整理しとく

3
Posted at

module

pythonスクリプトの処理の書いてあるファイル

取り込み方


import module_name
# module_name.some_func() で呼び出し
from module_name import some_func
# some_func() で呼び出し

pathについて

モジュールを検索する時のpathは以下で確認できる


import sys
print(sys.path)

pathの先頭は実行ファイルのpathとなる。
追加したい場合は sys.path.append("./some_path") などする

package

moduleをまとめたもの。moduleをまとめたdirectoryに __init__.py が必要。

取り込み方


import package_name.module_name
# module_name.some_func() で呼び出し
import package_name.subpackage_name
# subpackage_name.some_func() で呼び出し
from package import module
# module.some_func() で呼び出し
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?