name: Python slug: python version: 1.0.1 description: Write reliable Python avoiding mutable defaults, import traps, and common runtime surprises. metadata: {"clawdbot":{"emoji":"🐍","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}}
| Topic | File |
|---|---|
| Dynamic typing, type hints, duck typing | types.md |
| List/dict/set gotchas, comprehensions | collections.md |
| Args/kwargs, closures, decorators, generators | functions.md |
| Inheritance, descriptors, metaclasses | classes.md |
| GIL, threading, asyncio, multiprocessing | concurrency.md |
| Circular imports, packages, init.py | imports.md |
| Pytest, mocking, fixtures | testing.md |
小葱技能7w4.net持续更新中。
def f(items=[]) shares list across all calls — use items=None then items = items or []is checks identity, == checks equality — "a" * 100 is "a" * 100 may be Falsefor x in list(items):except: catches SystemExit and KeyboardInterrupt — use except Exception:UnboundLocalError when assigning to outer scope variable — use nonlocal or globalopen() without context manager leaks handles — always use with open():0.1 + 0.2 != 0.3 — floating point, use decimal.Decimal for moneyitertools.tee__init__ instead__init__ is not constructor — __new__ creates instance, __init__ initializesencoding='utf-8'这是一份专注于 Python 常见陷阱的实用速查包,涵盖类型、函数、并发、测试等多个方面,结构清晰、分类明确,适合快速查阅和避坑。优点是内容精炼、针对性强,Critical Rules 设计便于快速定位关键问题;不足之处在于部分主题讲解较浅,缺少代码示例和场景化指引,整体更像是错误清单而非全面的实践指南。基础避坑够用,但深度和系统性有提升空间。