Python 有用的资源
Official docs, style guide, packaging, and the references worth bookmarking.
Official Documentation
docs.python.org is versioned — switch between 3.10/3.12/3.13 on the page. Always check it before third-party blog posts for signatures.
| Resource | URL | Use it for |
|---|---|---|
| Language reference | docs.python.org/3/reference | Grammar and semantics |
| Standard library | docs.python.org/3/library | Module APIs |
| Tutorial | docs.python.org/3/tutorial | Guided learning |
| PEP index | peps.python.org | Design decisions |
| PyPI | pypi.org | Package search |
Style and Typing
PEP 8 defines naming, indentation and import order. Do not enforce it by hand — ruff formats and lints in one command.
pip install ruff
ruff check . # 静态检查
ruff format . # 格式化(兼容 black)
pip install mypy
mypy app/ --strict # 类型检查Packaging
Modern projects declare metadata and dependencies in pyproject.toml (PEP 621), build with build, publish with twine.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["fastapi>=0.110"]python -m build # 产出 dist/*.whl 与 *.tar.gz
twine upload dist/*Reading Source
For "why is it designed this way", the CPython source or the library's GitHub issues beat search engines.
import json
print(json.__file__) # 本地模块路径,直接打开看实现官方文档
docs.python.org 按版本发布,页面上可以直接切 3.10 / 3.12 / 3.13。查标准库函数签名时永远优先看它,而不是搜索结果里的第三方文章。
| 资源 | 地址 | 用途 |
|---|---|---|
| 语言参考 | docs.python.org/3/reference | 语法与语义 |
| 标准库 | docs.python.org/3/library | 模块 API |
| 教程 | docs.python.org/3/tutorial | 系统入门 |
| PEP 索引 | peps.python.org | 设计决策依据 |
| PyPI | pypi.org | 找包 |
风格与类型
PEP 8 定义命名、缩进、空行与 import 顺序。不要手写检查 —— 用 ruff 一条命令搞定格式化加静态检查。
pip install ruff
ruff check . # 静态检查
ruff format . # 格式化(兼容 black)
pip install mypy
mypy app/ --strict # 类型检查打包与发布
现代 Python 项目用 pyproject.toml(PEP 621)声明元数据与依赖,构建用 build,发布用 twine。setup.py 已不再是必需文件。
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["fastapi>=0.110"]python -m build # 产出 dist/*.whl 与 *.tar.gz
twine upload dist/*读源码
遇到「为什么这样设计」,直接看 CPython 源码或该库的 GitHub issue 比搜索更快。python -c "import x; print(x.__file__)" 能定位本地安装路径。
import json
print(json.__file__) # 本地模块路径,直接打开看实现