Improvements to the park simulation blog landing --- software development specification

  1. Why specification development:

    • Py all written in a file, the file loads slow, poor readability of the code, the query trouble
    • So we want a separate file py, py reasonable split into multiple files
  2. Configuration:

    • Unified same variables, such as the file path simulation blog landed in a multi-use park. In order to better modify this file path, file can be written at the top of this path points to a variable, the variable direct reference to the code. When you modify only modified this variable.
  3. File division:

    1. setting.py

      Profiles for placing some static parameters required for the project, such as file paths, database configuration, software default settings and so on. For example, the above mentioned file path.

    2. common.py

      Public component files, to place some common public assembly function, not a function of core logic, but rather to serve the entire program of public plug-in, call the program that is needed, such as decorators, password encryption, sequence capabilities, logging and so on.

    3. src.py

      The core file is stored in the main core logic functions.

    4. start.py

      Project Initiation Document, the purpose is conspicuous, easy to open

    5. Similarly register file

      File name is not fixed, file data storage, similar to a text database, the project will encounter some of the data stored in the file, in the case that interact, so to be set separately in this document.

    6. log file

      Storage log log file

  4. Divided specific directory

    blog
    |__bin
    |  |__start.py
    |
    |__conf
    |  |__settings.py
    |
    |__core
    |  |__src.py
    |
    |__db
    |  |__register
    |
    |__lib
    |  |__commmon.py
    |
    |__log
    |  |__access.log
    |__README
  5. According to the project directory structure, standardize simulation blog landed Park

    1. Configuration start.py

      import sys
      import os
      # print(os.path.dirname(__file__)) # 获取本文件所在文件夹即bin的绝对路径
      # print(os.path.dirname(os.path.dirname(__file__)))
      # 获取本文件所在文件夹bin所在的文件夹blog的绝对路径
      BATH_DIR = os.path.dirname(os.path.dirname(__file__))
      sys.path.append(BATH_DIR)
      
      from core.src import run
      if __name__ == '__main__':
          run()
      # 或
      # from core import src
      # if __name__ == '__main__':
          # src.run()
    2. Settings.py configuration file

      # 配置静态文件,不会轻易改变
      import os
      print(os.path.dirname(os.path.dirname(__file__)))
      # 获取当前文件所在的目录的上级目录,即blog
      print(os.path.join(os.path.dirname(os.path.dirname(__file__)), r'db\register'))
      
      file_name = os.path.join(os.path.dirname(os.path.dirname(__file__)), r'db\register') # 拼接出register的路径
    3. Common.py configuration file

      from core import src
      # 用src.status_dic来引用src中的status_dic
      # 在启动strat.py时,已经把blog的路径添加到sys.path中了,意味着,在整个项目中的任何py文件,都可以引用到blog项目目录下面的任何目录:bin,conf,core,db,lib,log这几个,所以此处可以直接引用src
    4. Src.py configuration file

      from conf import settings
      from lib import common
      # 用settings.file_name引用settings中的file_name
      # 用common.wrapper引用common中的装饰器
    5. README

      1. The basic functions of the software localization, software
      2. The method of running code: installation environment, start a command such as
      3. Brief instructions for use
      4. Code directory structure, a more detailed description can point the basic principles of software
      5. Frequently asked questions

Guess you like

Origin www.cnblogs.com/zyyhxbs/p/11104294.html