次のように編成された一連のpythonスクリプトがあります。
PythonScripts/
TypeAScripts/
TypeASet1Scripts/
example.py
TypeASet2Scripts/
TypeBScripts/
TypeBSet1Scripts/
TypeBSet2Scripts/
TypeCScripts/
TypeCSet1Scripts/
TypeCSet2Scripts/
CommonFunctions/
CommonFunctions.py
init.py
すべてのフォルダで。私が欲しいのは、example.py
where example.py
imports fromを実行できるようにすることCommonFunctions
です。フォルダー A、B、および C のスクリプトで同じことを行いたいと考えています。
絶対インポートでこれを行うには、次のようにします
import PythonScripts.CommonFunctions.CommonFunctions
ただし、これPythonScripts
は Python パスにある場合にのみ機能します。example.py
そのフォルダーで実行しているだけの場合は、そうではありません。で追加できますがsys.append()
、これは厄介な方法のようです。より良いアプローチはありますか?