python-mastery
Python Mastery
How to use this skill
Read SKILL.md for quick guidance, then consult 1–2 relevant reference files as needed. Do NOT read all reference files at once. For simple tasks, the quick principles below may suffice.
Reference files — when to read each one
| Reference | Read when... |
|---|---|
references/pythonic-idioms.md |
Writing any Python. PEP 8, unpacking, comprehensions, walrus operator, match, regex, anti-patterns. |
references/data-structures.md |
Lists, tuples, dicts, sets, containers, dates/times, file I/O, pathlib, JSON/CSV/TOML/YAML, databases. |
references/functions-and-generators.md |
Functions, closures, decorators, generators, comprehensions, recursion, memoization, backtracking. |
references/classes-and-design.md |
Class design, dataclasses, properties, inheritance, composition, protocols, contracts, iterative design. |
references/design-patterns.md |
Template Method, Strategy, Factory, Observer, State, Adapter, Facade, Composite, Decorator, etc. |
references/error-handling.md |
try/except/else/finally, custom exception hierarchies, context managers, assertions, chaining. |
references/concurrency.md |
GIL, threading, asyncio, multiprocessing, subprocess, synchronization, migration patterns. |
references/testing-and-quality.md |
Testing, mocking, type hints, debugging, profiling, performance optimization, packaging, web frameworks. |
Quick principles
- Explicit over implicit. Favor clarity over cleverness. Extract hard-to-read expressions into descriptively named helpers.
- Follow PEP 8.
lowercase_underscorefor functions/variables,CapitalizedWordfor classes,ALL_CAPSfor constants. 4-space indent, lines ≤ 79 chars. Useblackandruff. - Use the right data structure. Dicts → lookups, sets → membership, lists → ordered sequences, tuples → fixed records, deques → queues, dataclasses → structured data.
- Prefer composition over inheritance. Inherit only for true is-a relationships; otherwise compose or use mix-ins.
- Write for the reader. Code is read far more than written. Use descriptive names, docstrings, type hints, and small focused functions.
- Don't repeat yourself. Extract shared logic, but don't over-abstract — two occurrences may be coincidence, three is a pattern.
- Errors should never pass silently. Use exceptions, not return codes. Catch specific exceptions. Keep try blocks short.
- Test your code. Python defers nearly all checks to runtime. Automated tests are your compiler.
- Encapsulate what varies. Isolate changing parts from stable parts — the foundation of good design.
- Iterate toward good design. Well-designed code rarely emerges in one pass. Write, test, refactor, repeat. Backtracking is normal.
More from nkootstra/skills
compact-markdown
Compact, compress, or minify markdown files to use fewer tokens while preserving all information and meaning. Use this skill whenever the user wants to reduce the size of a markdown file, shrink a README, compress a SKILL.md or CLAUDE.md, minify documentation, or make any markdown more token-efficient. Trigger even if they just say "make this shorter" or "compress this" on a markdown file.
56code-complexity-audit
>-
49agents-md
Write, audit, and improve agent context files (AGENTS.md, CLAUDE.md) for AI coding agents. Use when creating or improving agent context for a codebase.
26adversarial-review
>
22create-agents
Write, audit, and improve AGENTS.md files for AI coding agents. Use when creating or improving agent context for a codebase.
14markdown-compact
Compact, compress, or minify markdown files to use fewer tokens while preserving all information and meaning. Use this skill whenever the user wants to reduce the size of a markdown file, shrink a README, compress a SKILL.md or CLAUDE.md, minify documentation, or make any markdown more token-efficient. Trigger even if they just say "make this shorter" or "compress this" on a markdown file.
2