Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Python で独自のパッケージを作成する場合、次のようなインポートを含める必要があり__init__.pyます。それとも、これらを使用しているファイル内にインポートする必要がありますか?ossys
__init__.py
os
sys
それらを使用するモジュールにモジュールをインポートします。
に配置import osする__init__.pyとos、パッケージのグローバル名前空間に配置されますが、を使用するモジュールの名前空間には影響しませんos。グローバル名前空間はモジュールまたはパッケージ間で共有されないためNameError、os.
import os
NameError