Skip to content

Commit 65809f5

Browse files
📝 更新Python文档,优化标准库推荐
- 将多个文档中的“相关库推荐”标题更改为“标准库推荐”,统一格式。 - 增加了对标准库的详细说明,包括`hashlib`、`random`、`math`等,提升了文档的实用性。 - 删除了冗余的内容,简化了文档,确保信息更加清晰易懂。 - 更新了异步编程、文件操作等相关库的推荐,增强了对Python核心概念的理解。
1 parent d01d406 commit 65809f5

File tree

12 files changed

+83
-25
lines changed

12 files changed

+83
-25
lines changed

docs/docs/选择编程语言/Python/10函数.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ b = [10, 11, 15]
353353
list(map(add, a, b)) # [12, 14, 19]
354354
```
355355

356-
## 推荐库
356+
## 标准库推荐
357357

358-
- functools: 提供高阶函数和装饰器
359-
- itertools: 提供迭代器工具
360-
- operator: 提供操作符函数
361-
- typing: 提供类型提示
358+
- functools: 提供高阶函数和装饰器工具,例如 `wraps``lru_cache` 等。
359+
- contextlib: 提供上下文管理器相关工具,如 `contextmanager``nullcontext`
360+
- itertools: 提供迭代器工具(排列组合、无限迭代器等)。
361+
- operator: 提供将运算符函数化的工具,便于与高阶函数搭配使用。
362+
- typing: 提供类型提示支持,让函数签名更清晰。

docs/docs/选择编程语言/Python/1变量.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ print(hash(a),hash(b))
383383
# 529344067295497451 529344067295497451
384384
```
385385

386-
## 相关库推荐
386+
## 标准库推荐
387387

388-
- hashlib: 更加丰富的hash方法
389-
- <Highlight color="g">typing: 对类型提示的支持</Highlight>
390-
- <Highlight color="g">pydantic: **第三方**数据验证模块</Highlight>
391-
- pydoc: 文档生成器和在线帮助系统
392-
- doctest: 测试交互式Python示例
388+
- builtins: 内置函数与常用类型的集合,例如 `id``hash`
389+
- keyword: 提供 Python 关键字列表,用于变量命名检查等场景。
390+
- hashlib: 提供多种安全哈希和摘要算法。
391+
- typing: 提供类型提示相关的类与工具,让代码更易于维护。
392+
- pydantic: <Highlight color="g">**第三方**数据验证与设置管理库,常用于配置与数据模型校验。</Highlight>

docs/docs/选择编程语言/Python/1数字.mdx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,8 @@ print(sum([1,2,3],10)) # 16
625625
```
626626

627627

628-
## 相关库推荐
628+
## 标准库推荐
629629

630-
- <Highlight color="g">random: 生成伪随机数</Highlight>
631-
- <Highlight color="g">math: 数学函数</Highlight>
632-
- <Highlight color="g">decimal: 十进制定点和浮点算术</Highlight>
633-
- numbers: 数值抽象基类
634-
- cmath: 复数数学函数
635-
- fractions: 有理数
636-
637-
- statistics: 数学统计函数
630+
- random: 生成伪随机数
631+
- math: 数学函数
632+
- decimal: 十进制定点和浮点算术

docs/docs/选择编程语言/Python/20类与对象.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,4 +1545,9 @@ class MyMetaClass(metaclass=Meta):
15451545

15461546
print(type(MyMetaClass)) # <class '__main__.Meta'>
15471547
print(MyMetaClass.class_id) # MyMetaClass_ID
1548-
```
1548+
```
1549+
1550+
## 标准库推荐
1551+
1552+
- dataclasses: 通过装饰器自动生成 `__init__``__repr__` 等方法,简化数据类定义。
1553+
- abc: 提供抽象基类支持,用于定义接口与抽象方法。

docs/docs/选择编程语言/Python/29文件操作.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,21 @@ with open("data.bin", "rb") as f:
219219
# record_id, value = modified_structured_mv[i]
220220
# print(f"Modified Record {i}: ID={record_id}, Value={value}")
221221
```
222+
223+
## 标准库推荐
224+
225+
- os: 提供与操作系统交互的 API,如文件路径、权限与进程相关操作。
226+
- pathlib: 面向对象的路径操作库,比传统字符串路径更易读、更安全。
227+
- glob: 使用通配符匹配文件路径,方便批量处理一组文件。
228+
- tempfile: 创建临时文件和临时目录,适合中间数据与测试场景。
229+
- io: 提供更底层、灵活的流接口(文本流、二进制流等)。
230+
- xml: 处理 XML 结构化标记数据。
231+
- html: 生成或解析 HTML 文本。
232+
- csv: 读写 CSV 文本文件的标准库。
233+
- json: 处理 JSON 文本与 Python 对象之间的序列化/反序列化。
234+
- zipfile: 读写 ZIP 压缩文件。
235+
- tarfile: 读写 TAR 归档文件。
236+
- compressio: 处理多种压缩格式的工具集合。
237+
- pickle: 将 Python 对象序列化到文件/字节流,或从中恢复。
238+
- sqlite3: 内置轻量级关系型数据库,常用于本地持久化存储。
239+
- struct: 在字节串与 C 结构体之间进行打包和解包,适合处理二进制文件格式。

docs/docs/选择编程语言/Python/2字符串.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,11 @@ print(format(123.456, '.2%')) # 12345.60%
852852
print(format(123.456, '.2e')) # 1.23e+02
853853
```
854854

855-
## 相关库推荐
855+
## 标准库推荐
856856

857-
- <Highlight color="g">io.StringIO:把内存中的一个字符串,当成一个文件来处理。</Highlight>
857+
- re: 正则表达式处理文本匹配与替换。
858+
- difflib: 计算文本差异,生成“diff”结果。
859+
- io.StringIO: 把内存中的字符串当作文件来读写,常用于测试与中间处理。
858860

859861
:::info
860862
假设你有一个函数,它要求传入一个文件对象作为参数,但你并不想真的在磁盘上创建一个文件。这时,你可以用 io.StringIO 创建一个内存中的“假文件”。

docs/docs/选择编程语言/Python/30异步编程.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,14 @@ async def process_stream():
306306

307307
asyncio.run(process_stream())
308308
```
309+
310+
## 标准库推荐
311+
312+
- asyncio: 核心异步 IO 框架,提供事件循环、协程调度等能力。
313+
- threading: 基于线程的并发模型,适合与异步 IO 结合处理少量 CPU 密集任务。
314+
- multiprocessing: 使用多进程绕过 GIL,适合 CPU 密集型任务的并行计算。
315+
- concurrent.futures: 提供统一的线程池/进程池接口(`ThreadPoolExecutor` / `ProcessPoolExecutor`)。
316+
- queue: 线程安全的队列,用于在线程/协程间传递任务与数据。
317+
- subprocess: 启动子进程并与之通信,常用于异步地调用外部命令。
318+
- socket: 低层网络编程接口,也是许多高层网络库的基础。
319+
- webbrowser: 使用系统默认浏览器打开 URL。

docs/docs/选择编程语言/Python/38代码执行与调试.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,16 @@ print(return_value) # None
103103

104104
return_value = eval("1 + 1") # 执行表达式,返回表达式的值
105105
print(return_value) # 2
106-
```
106+
```
107+
108+
## 标准库推荐
109+
110+
- sys: 提供与解释器交互的接口,如 `sys.argv``sys.exit` 等。
111+
- inspect: 运行时检查对象(函数、类、模块等)的结构,是调试与元编程的重要工具。
112+
- code: 提供交互式解释器相关工具,可以自定义 REPL 环境。
113+
- dis: 反汇编 Python 字节码,帮助理解代码执行细节与性能问题。
114+
- time: 提供时间相关函数,如计时、休眠等。
115+
- timeit: 用于精确测量小段 Python 代码的运行时间。
116+
- pdb: 内置交互式调试器,支持断点、单步执行、查看变量等操作。
117+
- logging: 标准日志系统,替代 `print` 进行可控的日志记录。
118+
- gc: 控制与调试垃圾回收行为,分析内存管理问题。

docs/docs/选择编程语言/Python/39模块.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,4 +782,11 @@ pyinstaller -F -i app.ico app.py --noconsole
782782
# 将数据文件添加到捆绑包中,中间使用分号分隔,前面是源目录地址,后面是目的目录地址
783783
pyinstaller -F -i app.ico app.py --add-data="C:\mediapipe\modules;mediapipe/modules" --noconsole
784784
```
785-
:::
785+
:::
786+
787+
## 标准库推荐
788+
789+
- ctypes: 调用 C 语言动态库,桥接底层系统能力。
790+
- argparse: 构建命令行接口的标准解决方案。
791+
- datetime / zoneinfo / calendar: 处理日期、时间与时区。
792+
- locale: 处理本地化、区域设置相关的格式与文本。

docs/docs/选择编程语言/Python/3序列.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,3 +1527,10 @@ def is_even(x):
15271527

15281528
list(filter(is_even, range(10))) # [0, 2, 4, 6, 8]
15291529
```
1530+
1531+
## 标准库推荐
1532+
1533+
- copy: 提供浅拷贝与深拷贝工具,处理列表、字典等可变序列时非常常用。
1534+
- enum: 定义枚举类型,让一组常量更具可读性与安全性。
1535+
- weakref: 提供弱引用支持,适合管理大型对象图、缓存等避免循环引用。
1536+
- pprint: 以更易读的方式“漂亮打印”复杂嵌套的列表、字典等数据结构。

0 commit comments

Comments
 (0)