I have the following file structure:
command.py
simulations
basis
basis.py
hamiltonian
hamiltonian.py
where the names without extensions are folders.
command.pyis importingbasis.pyandhamiltonian.pylike:
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.pyalone, but it needs to importbasis.py.In order for
command.pyto work fine, the import inhamiltonian.pyhas to befrom basis.basis import BasisIn order for hamiltonian.py to run on its own, the import needs to be
os.chdir('..')
from basis.basis import Basis
however this makescommand.pynot 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?