Python

👤 ivangdavila 📦 v1.0.1 ⭐ 4.2 ⬇️ 9.5K 下載
💻 開發程式設計 免費

📖 技能介紹


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"]}}


Quick Reference

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

Critical Rules

  • 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 False
  • Modifying list while iterating skips elements — iterate over copy: for x in list(items):
  • GIL prevents true parallel Python threads — use multiprocessing for CPU-bound
  • Bare except: catches SystemExit and KeyboardInterrupt — use except Exception:
  • UnboundLocalError when assigning to outer scope variable — use nonlocal or global
  • open() without context manager leaks handles — always use with open():
  • Circular imports fail silently or partially — import inside function to break cycle
  • 0.1 + 0.2 != 0.3 — floating point, use decimal.Decimal for money
  • Generator exhausted after one iteration — can't reuse, recreate or use itertools.tee
  • Class attributes with mutables shared across instances — define in __init__ instead
  • __init__ is not constructor — __new__ creates instance, __init__ initializes
  • Default encoding is platform-dependent — always specify encoding='utf-8'

    發現更多技能外掛,請訪問7w4.net。

🤖 AI 評測

這是一份專注於 Python 常見陷阱的實用速查包,涵蓋型別、函式、併發、測試等多個方面,結構清晰、分類明確,適合快速查閱和避坑。優點是內容精煉、針對性強,Critical Rules 設計便於快速定位關鍵問題;不足之處在於部分主題講解較淺,缺少程式碼示例和場景化指引,整體更像是錯誤清單而非全面的實踐指南。基礎避坑夠用,但深度和系統性有提升空間。

📊 多維度評分

適應性3.8
規範性4.1
有效性4.6
可靠性4.2
可信度4.3

📁 包含檔案 (9 個)

📄 SKILL.md 1.8 KB
📄 _meta.json 121 B
📄 classes.md 605 B
📄 collections.md 616 B
📄 concurrency.md 763 B
📄 functions.md 577 B
📄 imports.md 534 B
📄 testing.md 498 B
📄 types.md 505 B