Communitygithub.com

AholicK/zh-book-skills

当用户写或读 Python 入门级语法与标准库用法、看不懂报错信息、或需要一份「写法 + 参数口径」速查时调用本能力包:分支与循环、序列切片、列表与元组、字典与集合、字符串拆合与格式化、运算符优先级、输入输出、函数与 lambda、类与对象、异常处理、模块与 pip、文件与目录、数据库访问、进程与线程、Socket、正则、wxPython 窗口构造。 覆盖《Python背记手册》(OCR 整理稿,源文未署名)全部 20 个能力单元,每张卡都注明底本损毁位置与「本书未覆盖」的边界。 不适用于:现代工程实践(虚拟环境、依赖锁定、类型注解、with 上下文管理器、测试与调试器);第三方库的完整开发教程;以及需要底本缺失部分的场合(数据类型转换表、socket 创建语句、re 模块调用函数、wx.App 与主循环、open() 签名行)。

zh-book-skills 是什么?

zh-book-skills is a Cursor agent skill that 当用户写或读 Python 入门级语法与标准库用法、看不懂报错信息、或需要一份「写法 + 参数口径」速查时调用本能力包:分支与循环、序列切片、列表与元组、字典与集合、字符串拆合与格式化、运算符优先级、输入输出、函数与 lambda、类与对象、异常处理、模块与 pip、文件与目录、数据库访问、进程与线程、Socket、正则、wxPython 窗口构造。 覆盖《Python背记手册》(OCR 整理稿,源文未署名)全部 20 个能力单元,每张卡都注明底本损毁位置与「本书未覆盖」的边界。 不适用于:现代工程实践(虚拟环境、依赖锁定、类型注解、with 上下文管理器、测试与调试器);第三方库的完整开发教程;以及需要底本缺失部分的场合(数据类型转换表、socket 创建语句、re 模块调用函数、wx.App 与主循环、open() 签名行)。.

兼容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/AholicK/zh-book-skills/tree/HEAD/python-quick-reference

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Python Backnote Manual — Full Book Capability Entry

Triggering and Non-Triggering

Applicable: Consultations and tasks related to the capability domain of this book (see intent column in the routing table below). Not Applicable:

  • Non-syntax issues: program architecture design, performance tuning, engineering standards, code review
  • Modern engineering practices (not covered by this book): virtual environments, requirements/dependency locking, type annotations, with context managers, debuggers and test frameworks, exception chains and custom exceptions
  • Complete third-party library tutorials (wxPython / Pygame / Flask / web scraping frameworks are only name-to-purpose comparison tables, no runnable programs)
  • Parts where the source material is missing assembly diagrams: data type conversion function table (NR-02), open() signature line (NR-09), connect() call example (NR-10), Thread/Process start/join (NR-11), socket creation and import (NR-12), re calling functions (NR-13), wx.App and main loop (NR-14)

Core Principles (Always-on Quick Reference; Overview-type questions can be answered from here)

  1. The knowledge in this book is organized in a trio of "syntax pattern + parameter-by-parameter explanation + example result": memorize the form and the default value of each parameter to write correct code.
  2. Branching and looping have only two driving methods — execute while condition is true, re-evaluate after execution (while), or retrieve values one by one from an object (for); break exits the loop, continue skips the current round, else cannot appear alone.
  3. Lists, tuples, and strings share the same three-parameter slicing convention: includes start, excludes end, and slicing generates a new sequence (the original sequence remains unchanged).
  4. Before sorting, ask "do I still need the original order?" If yes, use sorted (doesn't modify the original list); if no, use sort (modifies in place).
  5. Error handling is split into three segments: try contains code that might error, except catches a specific exception and handles it, finally contains code that must run regardless; raise is used for "don't handle here", assert pins down an assumption you think is necessarily true.
  6. Files and databases both follow a two-layer structure of "get the object first, then call methods": open gets a file object; connect gets a connection object, then cursor() gets a cursor object — SQL must be sent to the cursor, and changes must be committed.
  7. The source material is damaged by OCR (tables collapsed into single columns, parentheses turned into letters O, curly braces turned into parentheses): all citations follow the original manuscript exactly, and no damaged entries are filled in based on common sense.

Capability Routing (Read this table first, then load 1 capability card based on intent)

User IntentRead FirstSupplementary/Notes
Write branch logic that executes only if a condition is met; choose between while and for; exit a loop early or skip an element (break / continue); fix syntax errors with else or reserved words; understand why a loop doesn't run; repeatedly ask or execute until a condition stops being true (typical while scenario)references/capabilities/control-flow-and-loops.mdreferences/capabilities/operator-precedence.md, references/capabilities/input-and-print.md, references/capabilities/list-comprehension.md, references/capabilities/exception-handling.md
Extract a segment from a sequence (first few, middle segment, every Nth element); slice a string; verify slice boundaries when you get one more or one fewer element; confirm if slicing modifies the original list/string; read someone else's x[1:5:2] and know which elements are selectedreferences/capabilities/sequence-slicing.mdreferences/capabilities/list-and-tuple-operations.md, references/capabilities/string-encoding-split-join.md
Count how many times an element appears or find its index; merge another list into the current one; iterate over a list with an index; generate a list or tuple by range, create an empty list; add a base value to a sumreferences/capabilities/list-and-tuple-operations.mdreferences/capabilities/sequence-slicing.md, references/capabilities/sort-vs-sorted.md, references/capabilities/list-comprehension.md, references/capabilities/dict-and-set-operations.md
Sort a list in ascending or descending order; keep the original order after sorting; sort in place without creating a new object; sort by a certain key (e.g., case-insensitive); decide whether to use sort or sorted in a piece of codereferences/capabilities/sort-vs-sorted.mdreferences/capabilities/list-and-tuple-operations.md, references/capabilities/function-definition-and-call.md
Generate a new list in one line; map items to a new list; filter elements that meet a condition; convert an incomprehensible comprehension back into a loopreferences/capabilities/list-comprehension.mdreferences/capabilities/list-and-tuple-operations.md, references/capabilities/control-flow-and-loops.md
Create a dictionary and look up by key; deduplicate data into a set; iterate over a dictionary to get key-value pairs; determine whether a specific type can be used as a key or set element; choose between del/pop/remove/clear to delete from a collectionreferences/capabilities/dict-and-set-operations.mdreferences/capabilities/list-and-tuple-operations.md
Resolve garbled text and encoding mismatches; split a string into fields by a delimiter; merge multiple strings into one; make encoding/decoding tolerant to illegal charactersreferences/capabilities/string-encoding-split-join.mdreferences/capabilities/sequence-slicing.md, references/capabilities/file-and-directory-operations.md, references/capabilities/string-formatting.md, references/capabilities/regex-construction.md
Insert variables into one line of output; control decimal places; write percentages; output binary/hexadecimal representations; choose between % and format()references/capabilities/string-formatting.mdreferences/capabilities/string-encoding-split-join.md, references/capabilities/input-and-print.md
Determine the evaluation order and result of an expression; expand compound assignments (+= etc.) into their unfolded form; confirm whether the result of a comparison/logical expression is True or False; figure out which parts of a conditional expression are evaluated first and whether parentheses are neededreferences/capabilities/operator-precedence.mdreferences/capabilities/control-flow-and-loops.md
Accept keyboard input from the user; write a prompt for input; use print to output variables or expression results; build a minimal skeleton for user interaction with input/print (conditions and loops in the skeleton see control-flow-and-loops)references/capabilities/input-and-print.mdreferences/capabilities/control-flow-and-loops.md, references/capabilities/string-formatting.md
Encapsulate repeated code into a function; define parameters with default values; make a function return one or multiple values; write a small temporary function with lambda; pass a function where a function object is needed (e.g., key parameter for sorting; target for concurrent scenarios see process-and-thread)references/capabilities/function-definition-and-call.mdreferences/capabilities/sort-vs-sorted.md, references/capabilities/exception-handling.md, references/capabilities/class-and-objects.md, references/capabilities/process-and-thread.md
Define a class and create instances; write instance methods and handle self position; use @property to create a computed attribute; use inheritance to reuse an existing class and override methodsreferences/capabilities/class-and-objects.mdreferences/capabilities/function-definition-and-call.md, references/capabilities/gui-window-construction.md
Determine whether a feature belongs to the standard library or requires a package; write import / from…import statements (including aliases and * wildcard); install, view, and uninstall third-party modules; troubleshoot ImportError / ModuleNotFoundErrorreferences/capabilities/module-import-and-pip.mdreferences/capabilities/database-access.md, references/capabilities/socket-communication.md
Handle errors gracefully instead of crashing; write try…except…finally and decide what goes in each block; don't handle an exception at the current level and raise it to the caller; use assert to expose assumptions the program considers necessarily true; locate errors by exception name (NameError / KeyError / ZeroDivisionError, etc.)references/capabilities/exception-handling.mdreferences/capabilities/function-definition-and-call.md, references/capabilities/file-and-directory-operations.md, references/capabilities/control-flow-and-loops.md
Write content to a file or read from it; can't write after opening a file (default is read-only); delete or rename a file; check file size, last modification time, and other metadata; handle differences between relative paths and full pathsreferences/capabilities/file-and-directory-operations.mdreferences/capabilities/exception-handling.md, references/capabilities/string-encoding-split-join.md
Save data to a database or query it; distinguish between connection object and cursor object responsibilities; suspicion of missing commit after modifying data; retrieve query results (next record / specified number / all); confirm what parameters connect() accepts and determine the driver module name based on database type (driver installation and import see module-import-and-pip)references/capabilities/database-access.mdreferences/capabilities/module-import-and-pip.md
Start a task using Process or Thread (write the call and parameters, including what to fill for target / args / kwargs); confirm whether process and thread constructor parameters are identical; understand what mutex.acquire()/release() does; determine what happens when acquire(blocking=False) can't get the lock; protect shared data read/written by multiple executorsreferences/capabilities/process-and-thread.mdreferences/capabilities/function-definition-and-call.md
Write the call sequence of a TCP server from binding to receiving data; confirm what value to fill for listen's backlog; explain why accept stops and waits (blocking wait); determine step to check for client connection failure (socket.error); look up the purpose of recv/send/sendall/recvfrom/sendtoreferences/capabilities/socket-communication.mdreferences/capabilities/module-import-and-pip.md
Construct a regex pattern string; look up meaning of metacharacters (., \w/\s/\d/\b, ^, $); choose repetition quantifiers for a position; select flags like ignore case, multiline, dotall; determine whether ^ and $ match the whole string or per linereferences/capabilities/regex-construction.mdreferences/capabilities/string-encoding-split-join.md
Read or rewrite wxPython window and widget constructors; look up wx.Frame parameters and omittable items; set read-only/password styles for input boxes; choose a sizer category for widget layout; confirm what to pass for parent of top-level windows vs. controlsreferences/capabilities/gui-window-construction.mdreferences/capabilities/class-and-objects.md

Non-capability queries:

  • Book title/author/chapters/full book overview → references/overview.md
  • Term explanation → references/glossary.md
  • Decision rule quick reference (when original text basis not needed) → references/cheatsheet.md
  • Full intent and keyword index (intents not covered in this table, check here first) → references/capability-index.md

Loading Rules

  • Each task reads this file first, then loads 1 capability card according to the routing table; load at most 2 cards when the task clearly spans multiple domains.
  • Overview/title-type questions do not load capability cards; answer using "Core Principles" and overview.md.
  • Intents that cannot be matched by either the routing table or capability-index.md should be clearly stated as outside the scope of this book, and not forced.

Boundaries and Stop Conditions

  • When a question requires an "assembly diagram" not present in the source material (see last item in out_of_scope), stop reasoning and clearly state "not covered by this book"; do not fill in or fabricate code that appears in the book based on common sense.
  • When a citation involves the mapping of the data type conversion function table (NR-02, the function name in the ord() row is overwritten by the next row), stop citing that table and indicate the location of the source material damage.
  • When the user needs verbatim citations for print materials, teaching, etc., remind them that the source material is an OCR-compiled draft (NR-15: symbol misidentification, tables collapsed into single columns, row concatenation) and they should first switch to a better source and re-run citation verification.

相关技能