- <section class="journey-section"><div><h2>Make failure explicit.</h2><p class="meta">Robust Python code distinguishes expected absence, broken assumptions, recoverable errors, and domain-specific failures.</p><ul class="journey-list"><li><a class="text-link journey-item-title" href="/examples/exceptions">Exceptions</a><p class="meta">signal and recover from errors</p></li><li><a class="text-link journey-item-title" href="/examples/assertions">Assertions</a><p class="meta">state internal assumptions</p></li><li><a class="text-link journey-item-title" href="/examples/exception-chaining">Exception Chaining</a><p class="meta">preserve the cause while translating an error</p></li><li><a class="text-link journey-item-title" href="/examples/exception-groups">Exception Groups</a><p class="meta">handle multiple failures together</p></li><li><a class="text-link journey-item-title" href="/examples/custom-exceptions">Custom Exceptions</a><p class="meta">name failures in the language of the problem domain</p></li><li><a class="text-link journey-item-title" href="/examples/warnings">Warnings</a><p class="meta">signal soft problems and deprecations</p></li></ul></div><figure class="journey-figure"><svg viewBox="-8 -14 336 128" width="336" height="128" xmlns="http://www.w3.org/2000/svg"><line x1="40" y1="20" x2="300" y2="20" stroke="#521000" stroke-width="0.6"/><text x="34" y="23" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">TRY</text><line x1="40" y1="40" x2="300" y2="40" stroke="#521000" stroke-width="0.6"/><text x="34" y="43" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">EXCEPT</text><line x1="40" y1="60" x2="300" y2="60" stroke="#521000" stroke-width="0.6"/><text x="34" y="63" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">ELSE</text><line x1="40" y1="80" x2="300" y2="80" stroke="#521000" stroke-width="0.6"/><text x="34" y="83" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">FINALLY</text><path d="M50,20 L110,20 L130,60 L200,60 L220,80 L290,80" stroke="#FF4801" stroke-width="1.4" fill="none"/><circle cx="290" cy="80" r="2.5" fill="#FF4801"/></svg><figcaption>try, except, else, and finally as parallel lanes; the path traced through them is the actual control flow.</figcaption></figure></section><section class="journey-section"><div><h2>Control resource and module boundaries.</h2><p class="meta">Cleanup, deletion, imports, and modules define where responsibilities begin and end.</p><ul class="journey-list"><li><a class="text-link journey-item-title" href="/examples/context-managers">Context Managers</a><p class="meta">pair setup with reliable cleanup</p></li><li><a class="text-link journey-item-title" href="/examples/delete-statements">Delete Statements</a><p class="meta">remove names, attributes, and items intentionally</p></li><li><a class="text-link journey-item-title" href="/examples/modules">Modules</a><p class="meta">split code into importable files</p></li><li><a class="text-link journey-item-title" href="/examples/import-aliases">Import Aliases</a><p class="meta">make imported names clear at use sites</p></li><li><a class="text-link journey-item-title" href="/examples/packages">Packages</a><p class="meta">show package directories, `__init__.py`, and public module boundaries</p></li><li><a class="text-link journey-item-title" href="/examples/virtual-environments">Virtual Environments</a><p class="meta">isolate dependencies for a project</p></li></ul></div><figure class="journey-figure"><svg viewBox="-8 -14 260 104" width="260" height="104" xmlns="http://www.w3.org/2000/svg"><circle cx="20" cy="48" r="14" fill="none" stroke="#521000" stroke-width="1.0"/><text x="20" y="52" font-family="'JetBrains Mono', 'IBM Plex Mono', Menlo, monospace" font-size="9" fill="#521000" text-anchor="middle">in</text><line x1="34" y1="48" x2="69.0" y2="48.0" stroke="#521000" stroke-width="1.0"/><polygon points="76,48 69.0,50.8 69.0,45.2" fill="#521000"/><rect x="78" y="36" width="86" height="24" fill="none" stroke="#521000" stroke-width="1.0"/><text x="121.0" y="52.0" font-family="'JetBrains Mono', 'IBM Plex Mono', Menlo, monospace" font-size="10" fill="#521000" text-anchor="middle">body</text><line x1="164" y1="48" x2="199.0" y2="48.0" stroke="#521000" stroke-width="1.0"/><polygon points="206,48 199.0,50.8 199.0,45.2" fill="#521000"/><circle cx="220" cy="48" r="14" fill="none" stroke="#521000" stroke-width="1.0"/><text x="220" y="52" font-family="'JetBrains Mono', 'IBM Plex Mono', Menlo, monospace" font-size="9" fill="#521000" text-anchor="middle">out</text><line x1="122" y1="60" x2="210" y2="48" stroke="#521000" stroke-width="0.6" stroke-dasharray="2 2"/></svg><figcaption>A context manager pairs setup with reliable cleanup; the raise path still routes through __exit__.</figcaption></figure></section><section class="journey-section"><div><h2>Handle operations that outlive one expression.</h2><p class="meta">I/O, testing, logging, subprocesses, and concurrency require different control boundaries from ordinary expressions.</p><ul class="journey-list"><li><a class="text-link journey-item-title" href="/examples/async-await">Async Await</a><p class="meta">await concurrent I/O-shaped work</p></li><li><a class="text-link journey-item-title" href="/examples/async-iteration-and-context">Async Iteration and Context</a><p class="meta">consume async streams and cleanup protocols</p></li><li><a class="text-link journey-item-title" href="/examples/logging">Logging</a><p class="meta">record operational events without using `print()`</p></li><li><a class="text-link journey-item-title" href="/examples/testing">Testing</a><p class="meta">write deterministic tests with `unittest` or `pytest`</p></li><li><a class="text-link journey-item-title" href="/examples/subprocesses">Subprocesses</a><p class="meta">run external commands safely</p></li><li><a class="text-link journey-item-title" href="/examples/threads-and-processes">Threads and Processes</a><p class="meta">contrast concurrency choices beyond `asyncio`</p></li><li><a class="text-link journey-item-title" href="/examples/networking">Networking</a><p class="meta">make HTTP or socket boundaries explicit</p></li></ul></div><figure class="journey-figure"><svg viewBox="-8 -14 296 112" width="296" height="112" xmlns="http://www.w3.org/2000/svg"><line x1="20" y1="28" x2="270" y2="28" stroke="#521000" stroke-width="0.6"/><text x="14" y="31" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">LOOP</text><line x1="20" y1="64" x2="270" y2="64" stroke="#521000" stroke-width="0.6"/><text x="14" y="67" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="8" fill="rgba(82, 16, 0, 0.7)" text-anchor="end" letter-spacing="0.5">CORO</text><rect x="40" y="58" width="34" height="12" fill="none" stroke="#521000" stroke-width="1.0"/><line x1="76" y1="64" x2="110" y2="28" stroke="#521000" stroke-width="0.6" stroke-dasharray="2 2"/><rect x="112" y="22" width="58" height="12" fill="none" stroke="#521000" stroke-width="1.0"/><line x1="172" y1="28" x2="206" y2="64" stroke="#521000" stroke-width="0.6" stroke-dasharray="2 2"/><rect x="208" y="58" width="34" height="12" fill="none" stroke="#521000" stroke-width="1.0"/><text x="95" y="16" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="9" fill="rgba(82, 16, 0, 0.7)" text-anchor="middle">await</text><text x="190" y="16" font-family="-apple-system, 'Source Sans Pro', sans-serif" font-size="9" fill="rgba(82, 16, 0, 0.7)" text-anchor="middle">resume</text></svg><figcaption>On await, the coroutine yields to the loop; the loop runs other work and resumes when the awaitable is ready.</figcaption></figure></section>
0 commit comments