Python project structure and relative imports

I am new to Python and I have searched google many times and read some articles on relative imports, etc. Even though I can't get it to work. Please consider my following project structure:

/Project
    /docs
    /log
    /prev
    /src
        a.py
    /tests
        /tests1
            b.py
        /tests2
    .gitignore
    README.txt
    program.py

And I'm trying to import a class from a file a.pyinside a script b.py. Generally speaking, the script b.pyshould have an import string a.py. I read several articles about using files __init__.py, where should I put them? And should I somehow change PYTHONPATHhow? And the last question, is the project structure OK? Thanks for your time and help!

+4
1

python (sys.path):

import sys
sys.path.insert(0,'../..')

from a import class_name
+1

Source: https://habr.com/ru/post/1623843/


All Articles