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,
withcontext 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/Processstart/join(NR-11),socketcreation and import (NR-12),recalling functions (NR-13),wx.Appand main loop (NR-14)
Core Principles (Always-on Quick Reference; Overview-type questions can be answered from here)
- 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.
- 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);
breakexits the loop,continueskips the current round,elsecannot appear alone. - 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).
- Before sorting, ask "do I still need the original order?" If yes, use
sorted(doesn't modify the original list); if no, usesort(modifies in place). - Error handling is split into three segments:
trycontains code that might error,exceptcatches a specific exception and handles it,finallycontains code that must run regardless;raiseis used for "don't handle here",assertpins down an assumption you think is necessarily true. - Files and databases both follow a two-layer structure of "get the object first, then call methods":
opengets a file object;connectgets a connection object, thencursor()gets a cursor object — SQL must be sent to the cursor, and changes must be committed. - 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 Intent | Read First | Supplementary/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.md | references/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 selected | references/capabilities/sequence-slicing.md | references/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 sum | references/capabilities/list-and-tuple-operations.md | references/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 code | references/capabilities/sort-vs-sorted.md | references/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 loop | references/capabilities/list-comprehension.md | references/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 collection | references/capabilities/dict-and-set-operations.md | references/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 characters | references/capabilities/string-encoding-split-join.md | references/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.md | references/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 needed | references/capabilities/operator-precedence.md | references/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.md | references/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.md | references/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 methods | references/capabilities/class-and-objects.md | references/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 / ModuleNotFoundError | references/capabilities/module-import-and-pip.md | references/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.md | references/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 paths | references/capabilities/file-and-directory-operations.md | references/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.md | references/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 executors | references/capabilities/process-and-thread.md | references/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/sendto | references/capabilities/socket-communication.md | references/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 line | references/capabilities/regex-construction.md | references/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. controls | references/capabilities/gui-window-construction.md | references/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.