Library Search
结果页装饰器、生成器与上下文管理器
在 知识库 中找到 8 个匹配结果。
知识库
知识库
8 个 装饰器、生成器与上下文管理器 # Python 进阶示例:装饰器、生成器与上下文管理器
## 目标
掌握 Python 三大进阶特性:**装饰器**、**生成器**、**上下文管理器**,理解它们在真实项目中的应用。
---
## 1. 装饰器(Decorator)
装饰器在不修改原函数的情况下,为其增加额外功能。
### 基础装饰器
```python
import time
import functools… 2% MyBatis-Plus 实战入门 // 查询单个
User user = userMapper.selectOne(
new LambdaQueryWrapper<User>().eq(User::getEmail, "test@test.com")
);
// 只查指定字段
wrapper.select(User::getId, User::getName);
// 排除字段
wrapper.select(User.… 2% 01-hello-world-基础语法 # ===== 7. 文件读写 =====
with open("demo.txt", "w", encoding="utf-8") as f:
f.write("Hello from Python!\n")
f.write(f"Generated by {name}\n")
with open("demo.txt", "r", encoding="utf-8") as f:… 2% 飞桨生态系统:ERNIE + 动静统一 + 产业套件 texts = ["这部电影太棒了!", "服务态度很差,不推荐。"]
inputs = tokenizer(texts, padding=True, return_tensors="pd")
logits = model(**inputs)
predictions = paddle.argmax(logits, axis=-1)
print(predictions) # [1, 0]
```… 2% 02-进阶工程化教程 ```python
# 类似列表推导式,但惰性求值
squares = (x**2 for x in range(10))
print(next(squares)) # 0
print(next(squares)) # 1
# 内存对比
import sys
list_comp = [x**2 for x in range(10_000)]
gen_exp = (x**2 for x in… 2% 进阶:自定义封装与分层原理图设计 # 钻孔文件
kicad-cli pcb export drill \
--output "$OUTDIR/" \
--format excellon \
--excellon-zeros-format decimal \
"$PROJECT.kicad_pcb"
# BOM
kicad-cli sch export bom \
--output "$OU… 1% Pillow 图像处理完全指南 # 保存
out_path = output_dir / f"processed_{filepath.stem}.jpg"
img.save(out_path, "JPEG", quality=85, optimize=True)
print(f"✓ {out_path}")
batch_process("./raw_pho… 1% 02-restful-api ```bash
# 获取所有书籍
curl http://localhost:5000/api/books
# 获取单本书
curl http://localhost:5000/api/books/1
# 创建新书
curl -X POST http://localhost:5000/api/books \
-H "Content-Type: application/json" \
-… 1%