Module 01 · Python Coding Practices and Packaging Concepts
Module 1 Summary: Python Coding Practices and Packaging Concepts模块 1 总结:Python 编程实践与打包概念
Congratulations! You have completed this module. At this point, you know that:
恭喜!您已完成本模块。此时,您知道:
- The application development lifecycle has seven phases, including:
应用开发生命周期包括七个阶段,具体如下: - Requirement Gathering: You collect user, business, and technical requirements for the app
需求收集:您收集应用程序的用户、业务和技术需求 - Analysis: You analyze the requirements
分析:您分析需求 - Design: You design the complete solution
设计:您设计完整解决方案 - Code and test: You build and test the different components of the app
编写和测试:您构建和测试应用程序的不同组件 - User and system test: Users test the app for usability, and you perform system integration testing and performance testing
用户和系统测试:用户测试应用程序的可用性,您执行系统集成测试和性能测试 - Production: The application is available to all end users
生产:应用程序对所有最终用户开放 - Maintenance: You upgrade or fix any user or system issues
维护:您升级或修复任何用户或系统问题 - All web apps are APIs, but not all APIs are web apps. Both share data between apps, but not all APIs require networks like web apps do.
所有网络应用程序都是 API,但并非所有 API 都是网络应用程序。它们都在应用程序之间共享数据,但并非所有 API 都需要像网络应用程序那样的网络。 - The PEP8 guidelines for code readability include the following:
PEP8 代码可读性指南包括以下内容: - Four spaces for indentation
使用四个空格进行缩进 - Blank lines to separate functions and classes
使用空行分隔函数和类 - Spaces around operators and after commas
操作符周围和逗号后面的空格 - The PEP8 coding conventions for consistency and manageability include:
PEP8 编码规范为了保持一致性和可管理性包括: - Add larger blocks of code inside functions
在函数内部添加较大的代码块 - Name functions and files using lowercase with underscores
使用小写字母和下划线来命名函数和文件 - Name classes using CamelCase
使用驼峰命名法命名类 - Name constants in capital letters with underscores separating words
使用大写字母和下划线命名常量 - To ensure that your code adheres to the predefined style and standard without executing the code, you can use the Static code analysis method.
为了确保您的代码符合预定义的样式和标准,而无需执行代码,您可以使用静态代码分析方法。 - Unit testing is a method to validate if code units are operating as designed. You must test every unit before integration with the final codebase.
单元测试是一种验证代码单元是否按设计运行的方法。在最终代码库集成之前,您必须测试每个单元。 - To create a package: 创建一个包:
- Create a folder with the package name
创建一个以包名命名的文件夹 - Create an empty init.py file
创建一个空的 init.py 文件 - Create the required modules
创建所需的模块 - In the init.py file, add code to reference the modules needed in the package
在 init.py 文件中,添加代码以引用包中所需的模块 - You can verify the package via the bash terminal in a Python shell.
您可以在 Python 壳中的 bash 终端中验证该包。