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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -