I just want to be able to execute the file func2B.py, both by executing func2B.py and by executing main.py (main.py executes func2B.py).
When I try to do so, I get several errors such as "no module named ...", or "func3 is not defined", depending on what i insert in the different init.py files. I tried many combinations of different imports but I can't figure out how to properly set the imports.
I work with python 3.6 and a Win10 machine.
I have the following file structure:
folder1\
__init__.py # empty file
main.py
func1.py
folder2\
__init__.py # empty file
func2.py
func2B.py
folder3\
__init__.py # empty file
func3.py
content of main.py:
import func1
func1.main()
# [works] execute function (func2) stored in another folder (folder2)
import folder2.func2
folder2.func2.main()
# [works] execute function (func2) stored in another folder (folder3)
import folder2.folder3.func3
folder2.folder3.func3.main()
# [doesn't work] execute function (func2B) stored in another folder (folder2)
# [doesn't work] the function (func2B) calls another function (func3)
import folder2.func2B
folder2.func2B.main()
content of func1.py
def main():
print('executing func1')
if __name__ == '__main__':
main()
content of func2.py
def main():
print('executing func2')
if __name__ == '__main__':
main()
content of func2B.py
def main():
print('executing func2B, which executes func3')
func3.main()
if __name__ == '__main__':
main()
content of func3.py
def main():
print('executing func3')
if __name__ == '__main__':
main()