Design a clear hierarchy of directories to achieve these two points:
- High readability: People who are unfamiliar with the project can read the directory structure at a glance.
- High maintainability: Over time, the size of the code/configuration increases, the project structure is not chaotic, and can still be well organized.
Directory Organization mode:
Atm
├──bin
│└──start.py
├──conf
│└──settings.py
├──core
│└──test_main.py
├──db
│└──db.json
├──docs
├──lib
│└──common.py
├──log
│└──access.log
└──readme
Simply explain:
- Bin: Store Some executable files of the project, of course you can name script/and so on.
- Conf: Configuration file directory
- Core: Kernel Code Catalog
- DB: Data Catalog
- Docs: Store some documentation.
- Lib: library files, storing some custom modules and packages
- LOG: Logs directory
- README Installation Instructions
About the content of the Readme:
The role of the Readme is to describe the project's information and to give the reader a quick overview of the project.
It needs to illustrate several things:
- Software positioning, the basic functions of the software.
- How to run your code: Installation environment, startup commands, and so on.
- Brief instructions for use.
- Code directory structure Description, more detailed can explain the basic principles of the software.
- FAQ's description.
About Requirements.txt and setup.py
In general, use setup.py to manage the packaging, installation, and deployment of your code. The industry standard notation is to use Python's popular packaging tools Setuptools to manage these things. This approach is commonly used in open source projects. But the core idea here is not to use standardized tools to solve these problems, but to say that a project must have an installation deployment tool that can quickly and easily install the environment on a new machine, deploy the code, and run the program. I've stepped on the pit. When I first started working on Python writing projects, installing the environment, deploying the code, and running the program were all done manually and encountered the following issues: 1, Install the environment often forget that recently added a new Python package, the result of running on the line, the program is wrong. 2 3 If you rely on a lot of packages, it's time-consuming to install these dependencies one by one. 4 When a new classmate starts writing a project, it is very troublesome to run the program because it may often forget how to install various dependencies. Setup.py can automate these things to improve efficiency and reduce the probability of errors. " The complex thing is automated, and things that can be automated must be automated. " is a very good habit. Setuptools documents are huge, just contact, it may not be very good to find an entry point. The way to learn technology is to see how others are used, you can refer to a Python web framework, flask is how to write: setup.py of course, it is easy to write an installation script (deploy.sh) instead of setup.py can not be.
setup.py Description
This file exists for the purpose of:1, convenient for developers to maintain software package dependencies. Add the new packages in the development process to this list to avoid missing packages when the setup.py installation is dependent. 2. It is convenient for readers to clarify which Python packages the project uses. The format of this file is that each line contains a packet-dependent description, usually flask>=0.10, which requires that this format be recognized by the PIP, so that it can be easily install-r by PIP. Requirements.txt to put all the Python package dependencies in place.
requirements.txt Description
about how to use the configuration file:
1. The configuration file is written in one or more Python files, such as conf.py here. 2, which module in the project use this configuration file directly through the import conf this form to use the configuration in the code. I do not agree with this approach:1, which makes unit testing difficult (because the module relies on external configuration)2, on the other hand, the configuration file as the interface of the user control program, it should be possible for users to freely specify the path of the file. 3, the program component reusability is too poor, because this through all modules of code hard-coded way, so that most of the modules rely on conf.py this file. So, I think the use of configuration, the better way is that1, the configuration of the module can be flexibly configured, not affected by external configuration files. 2, the configuration of the program can also be flexibly controlled. Can support this idea is, with Nginx and MySQL students know that nginx, MySQL these programs are free to specify the user configuration. Therefore, you should not import conf directly into your code to use the configuration file. The conf.py in the above directory structure is a configuration sample given, not a configuration file that is directly referenced in the program. You can let the program read the configuration by assigning a configuration path to the main.py startup parameter. Of course, here's conf.py you can change a similar name, such as settings.py. Or you can use other formats to write configuration files, such as Settings.yaml.
configuration File Description
About Jobs:
Job Prerequisite Knowledge:
- Module Import
- Directory Organizational Structure
- Function
- Third-party modules (serialization, logging)
- Decorative Device
- Using process-oriented development (ATM programs are infrequently changed programs)
Software development process:
- Drawing flowchart
- Write a Readme
- Develop programs in strict accordance with software development specifications
Job Requirements:
Analog implementation of an ATM + shopping mall Program
- Quota 15000 or Custom
- Realize shopping mall, buy things to add shopping cart, call credit card interface Checkout
- Can withdraw, handling fee 5%
- 22nd monthly Billing, 10th monthly repayment date, overdue, according to the total amount owed 5 daily interest
- Multi-Account Login support
- Support transfer between accounts
- Record monthly daily consumption flow
- Provide repayment interface
- ATM Record Operation Log
- Provide management interface, including adding account, user quota, freezing account, etc...
- Decorator for user authentication
Sample Code HTTPS://GITHUB.COM/TRIAQUAE/PY3_TRAINING/TREE/MASTER/ATM
Simple flowchart: https://www.processon.com/view/link/589eb841e4b0999184934329
Reference Link: http://www.cnblogs.com/alex3714/articles/5765046.html
Python-based software catalog structure specification