Python project structure and relative imports

夙愿已清 提交于 2019-12-01 04:33:19

问题


I'm new to Python and I searched google a lot and read some articles about relative imports etc. Despite the fact that I am unable to get it working. Please, consider my following project structure:

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

And what I'm trying to achieve is to import a class from file a.py inside of the script b.py. Generally speaking, script b.py should have line with import of a.py. I've read some articles about using __init__.py files, where should I put them? And should I change PYTHONPATH some way, how? And last question, is project structure OK? Thank you for your time and help!


回答1:


You need to use Python unit tests and you can start with how-do-i-run-all-python-unit-tests-in-a-directory.



来源:https://stackoverflow.com/questions/34732916/python-project-structure-and-relative-imports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!