I have the following file structure:
command.py
simulations
basis
basis.py
hamiltonian
hamiltonian.py
where the names without extensions are folders.
command.py
is importingbasis.py
andhamiltonian.py
like:
from basis.basis import Basis
from hamiltonian.hamiltonian import Hamiltonian
where Basis
and Hamiltonian
are two classes.
I can run command.py
fine, all the imports are Okay.
Now, I want to work with
hamiltonian.py
alone, but it needs to importbasis.py
.In order for
command.py
to work fine, the import inhamiltonian.py
has to befrom basis.basis import Basis
In order for hamiltonian.py to run on its own, the import needs to be
os.chdir('..')
from basis.basis import Basis
however this makescommand.py
not work anymore.
--
1) Can I somehow run the os.chdir('..')
only if hamiltonian.py
is run on its own? Like with if name == 'main'
?
2) Is there a more elegant solution to this?