# my-python **Repository Path**: sn-yang/my-python ## Basic Information - **Project Name**: my-python - **Description**: 我的 Python 学习仓库 - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-09 - **Last Updated**: 2024-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 我的系列 - Python ## 特性 - [x] Python [基本语法](./src/lang/basic.py) - [x] Python [基本语句](./src/lang/statements.py) - [x] Python [格式化](./src/lang/format.py) - [x] Python [数据模型](./src/lang/data_model.py) - [x] Python [协程](./src/lang/coroutines.py) - [x] Python [数据转换](./src/utils/convertor.py) - [ ] Python 的常用工具类代码 - [x] [文件功能](./src/utils/file_util.py) - [x] [MySQL 功能](./src/utils/db_client.py) - [x] [Excel 工具类](./src/utils/excel_util.py) - [x] [Request 工具类](./src/utils/request_util.py) - [ ] 字符串、正则表达式工具类 - [ ] 代码生成工具 - [x] 单元测试代码 - [ ] 安装包生成 ## 开发环境 ### 准备开发环境 #### 准备开发环境:系统工具 - 安装 python - 安装 git - 安装 vscode #### 准备开发环境:vscode - 安装 vscode 扩展: Code Runner - 安装 vscode 扩展: Python Extension Pack #### 准备开发环境:Python - 配置 Python 国内源。 创建文件 `%USERPROFILE%/pip/pip.ini`,输入以下内容并保存。 ```ini [global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com ``` - 安装 Python 开发辅助包 ```sh # 升级 python 的包管理工具 python -m pip install --upgrade pip # flake8, black, pylint, isort: 用于代码的规范检查和格式化 # mypy: 支持强类型 pip install mypy flake8 pylint black isort # poetry: 是一个 Python 虚拟环境和依赖管理的工具 pip install poetry # poetry: 检测版本(直接运行) poetry --version # poetry: 检测版本(以 python 模块方式运行) python -m poetry --version # 设置 poetry 国内源 poetry source add aliyun "http://mirrors.aliyun.com/pypi/simple/" ``` #### 准备开发环境:项目初始化 - 使用 vscode 打开仓库的本地目录 - 激活 python 虚拟环境 ```sh # 激活 python 虚拟环境 poetry shell # 安装项目的依赖包 poetry install ``` ### 开发: 打开项目 - 使用 vscode 打开仓库的本地目录 - 激活 python 虚拟环境 ```sh # 激活 python 虚拟环境 poetry shell ``` ### 开发: 运行单元测试 ```sh ./unittest.sh ``` ## 代码规范 - [官方建议: Python 代码风格(English)](https://peps.python.org/pep-0008/) - [Google Python Guildlines](https://google.github.io/styleguide/pyguide.html) - [命名规范] | 名称 | 标识 | 备注 | | -------------------- | ------------------------------------ | ---- | | 小写 | `lowercase` | | | 小写(带下划线) | `lower_case_with_underscores` | | | 大写 | `UPPERCASE` | | | 大写(带下划线) | `UPPER_CASE_WITH_UNDERSCORES` | | | 首字母大写 | `CapitalizedWords` | | | 首字母小写 | `mixedCase` | | | 首字母大写(带下划线) | `Capitalized_Words_With_Underscores` | 丑 | 缩写被认为是一个单词: 在 `CamelCase` 中,使用 `Uuid` 而不是 `UUID`。 | 元素 | 规范 | 备注 | | ------------------ | ------------------------------- | -------------------------------------------------- | | 包、模块名 | `lower_case_with_underscores` | 短, 全部小写,不鼓励使用下划线 | | 目录、文件名 | `lower_case_with_underscores` | 同上 | | 类名 | `CapitalizedWords` | 注意不同于 python 内置类的规范 | | 类型变量名 | `CapWords` | 建议协变量带后缀 `_co`,逆变量类型带后缀 `_contra` | | 异常名 | `CapitalizedWords` | 带后缀 `Error` | | 全局变量名 | `lower_case_with_underscores` | | | 方法名 | `lower_case_with_underscores` | | | 变量名 | `lower_case_with_underscores` | | | 参数名 | `lower_case_with_underscores` | | | 非公开方法、变量名 | `__lower_case_with_underscores` | 带前缀 `__` | | 常量 | `UPPER_CASE_WITH_UNDERSCORES` | |