Basically I have written two modules for my Python Program. I need one module to import the other module.
Here is a sample of my file structure.
test_app
main.py
module_1
__init__.py
main.py
module_2
__init__.py
main.py
Main.py is able to import either of the two modules, but I need module_1 to import module_2, is that possible?
Yes. If your
PYTHONPATHenvironment variable is set totest_app, you should be able to importmodule1frommodule2and vice versa.I assume that you run your program like this:
and that the program imports
module1.main, which in turn importsmodule2.main. In that case there is no need to alter the value ofPYTHONPATH, since Python has already added the test_app directory to it. See the Module Search Path section in the Python docs.