I am struggling with a dummy question about importing classes from another sub-directory and I can’t find satisfying solution. Here is the context: I have a root folder, let’s call it project, that contains two sub folders, called app and test.
In app, I have my classes files, class1.py and so on. In test, I have test_class1.py to hold my unit test class. Seems to be some standard folder structure to me. How do I import class1 from test_class1.py? So far I append ‘../app’ to my sys.path but it looks so ugly to me! I tried from ..app import class1
and so many other combinations unsuccessfully.
Second question: Are __init__.py
still needed in python 3.6+?
Thanks for your help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…