How to organize a Python Project?

后端 未结 8 2008
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 16:35

I\'m new to Python and I\'m starting a mini Project, but I have some doubts on how to organize the folders in the \"Python Way\".

I\'m using PyDev in my

8条回答
  •  滥情空心
    2020-12-22 16:57

    Before deciding on a project structure, it's good to ask yourself what the purpose of the project is going to be. Is this going to be one off analysis? A toy concept you want to investigate? A full blown project you intend to distribute? The amount of effort you want to put into structuring your project will be different.

    • If it's a one off analysis, I like to use ipython notebooks. The notebook will capture the flow of your thoughts, and you can add notes in markup to your code for later reference.
    • If it's a toy concept you want to investigate, I find a simple, quick approach to work best. You want to be able to quickly implement your concept to discover if it's even feasible and thus worth spending more time on it. Part of Python's philosophy is 'Don’t try for perfection because “good enough” is often just that.' You can always come back later and structure your project in a way that follows best software engineering practices.
    • If you want to structure your project so you can later distribute it, and so that it scales to many modules I recommend the following structure:

      projectname
       ├── MANIFEST.in
       ├── setup.py
       ├── README
       ├── .gitignore
       ├── .git
       ├── projectname_env
       └── projectname
           ├── __init__.py
           ├── subpackageone
           │   ├── __init__.py
           │   ├── second_module.py
           │   ├── tests
           │   │   └── test_second_module.py
           │   └── models
           │       └── model1
           ├── first_module.py   
           └── tests
               └── test_second_module.py
      

    The detailed reasons why I like this structure are in my blog post, but the basic gist is that the hierarchically lower level projectname directory contains your actual project. Alongside it are all the tools that help manage (git) and package (setup.py, MANIFEST.in) it.

提交回复
热议问题