使い方
参考:
モジュール | Python 3.x ドキュメント [公式]
モジュールの内容を確認する
モジュールをインポートして、モジュールに含まれるメソッドと変数の一覧を確認する。
>>> import sys >>> dir(sys)
ヘルプを表示する。
>>> help(sys) >>> help(sys.path)
参考:
モジュールで定義されているモノを調べる | Bye Bye Moore
dir() | Python 3.x ドキュメント [公式]
help() | Python 3.x ドキュメント [公式]
How to find out what methods, properties, etc a python module possesses – Stack Overflow
import
sys
をインポートする。
import sys
別の名前を付けてインポートする。
import numpy as np
モジュールのメソッドやプロパティを個別にインポートする。
from math import sin, cos, pi
参考:
Python 3 でのファイルの import のしかたまとめ – Qiita
Python の import についてまとめる – Qiita
Python のモジュールと import と from 入門 – Qiita
Python の import 文ってなに? | 民主主義に乾杯
import 文 | Python 3.x ドキュメント [公式]
インポートシステム | Python 3.x ドキュメント [公式]
相対参照
参考:
パッケージ内参照 | Python 3.x ドキュメント [公式]
__init__.py
参考:
Python の __init__.py とは何なのか – Qiita
属性
__name__
__doc__
__file__
__dict__
参考:
Python Module Attributes: name, doc, file, dict | TutorialsTeacher
プロパティ
参考:
Can modules have properties? – Stack Overflow
Can modules have properties the same way that objects can? – Stack Overflow
properties on a module? – Stack Overflow
Use alias for a property in Python at module level – Stack Overflow
__dict__
参考: