跳至主要内容
小龙虾小龙虾AI
🤖

Python

Write reliable Python avoiding mutable defaults, import traps, and common runtime surprises.

下载4.7k
星标5
版本1.0.1
写作创作
安全通过

技能说明


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

TopicFile
Dynamic typing, type hints, duck typingtypes.md
List/dict/set gotchas, comprehensionscollections.md
Args/kwargs, closures, decorators, generatorsfunctions.md
Inheritance, descriptors, metaclassesclasses.md
GIL, threading, asyncio, multiprocessingconcurrency.md
Circular imports, packages, init.pyimports.md
Pytest, mocking, fixturestesting.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'

如何使用「Python」?

  1. 打开小龙虾AI(Web 或 iOS App)
  2. 点击上方「立即使用」按钮,或在对话框中输入任务描述
  3. 小龙虾AI 会自动匹配并调用「Python技能完成任务
  4. 结果即时呈现,支持继续对话优化

相关技能