import - Importing From Sister Subdirectories in Python? -
so, i've seen few similar questions on stack overflow, nothing seems address issue, or general case. so, question fixes that, , stops headaches. have git repo of form:
repo/ __init__.py sub1/ __init__.py sub1a/ __init.py mod1.py sub2/ __init__.py mod2.py
how import mod2.py mod1.py , vice versa, , how change depending on whether mod1.py or mod2.py scripts (when each respectively importing-- not being imported)?
the simplest solution put directory containing repo
in pythonpath
, , use absolute-path imports, e.g. import repo.sub2.mod2
, on.
any other solution going involve hackery if want cover cases you're invoking both python files directly scripts arbitrary directories - sys.path
mangling accomplish same thing setting pythonpath
, without having have user set it.
Comments
Post a Comment