首页›Trey Hunner›文章

Reorganizing Python's sys module

Trey Hunner · 2026年8月13日

AI 摘要 AI 生成,可能有误

作者提出了一个思想实验:将 Python 的 sys 模块——它就像一个拥有 115-121 个属性的“杂物抽屉”——重新组织成九个假想的子模块,例如 sys.cli、sys.imports、sys.io、sys.memory 和 sys.runtime。作者展示了一个名为“newsys”的概念验证,它利用模块级的 __getattr__ 和 __setattr__ 技巧(通过 ModuleType 子类实现),使 sys.stdout 等旧的扁平名称与嵌套结构保持同步。最终,作者得出结论:由于巨大的向后兼容性挑战,这样的重构很可能永远不会发生;作者并不将其视为一项严肃的提案,而是把它当作一个实用的经验教训——子模块可以帮助驯服过度膨胀的 utils 风格模块。

The sys module is the primary junk drawer of the Python standard library.

A good junk drawer holds miscellaneous items that don’t have another sensible home.

I often think of utils modules as “junk drawer” modules. I believe that both utils modules and junk drawers have their purpose, but junk drawers can get out of hand.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Trey Hunner

Python Black Friday & Cyber Monday sales (2026)

AI 摘要This is the author's ninth annual roundup of Python-related Black Friday and Cyber Monday deals for 2026, listing discounts from creators such as Python Morsels, Talk Python, Data School, Reuven Lerner, Brian Okken, and Mike Driscoll, along with Django-related sales compiled by Adam Johnson. The author also highlights their own sale offering lifetime access to Python Morsels, an exercise-driven Python skill-building platform, for $649 through November 30. Readers are invited to submit additional Python-related deals to be added to the list.

Python Morsels Lifetime Access Sale (2026)

AI 摘要Through November 30, Python Morsels is offering lifetime access to its Python skill-building service for $649 (compared to the usual $240 per year), marking the first time the offer includes the new Daily Recall spaced repetition system launched in September. The service is built around deliberate practice through exercises, hints, and screencasts, and lifetime access covers 270+ exercises, 240+ screencasts, 300+ articles, 500+ Daily Recall questions, courses, and all future content updates. A 7-day free trial and a 30-day money-back guarantee are available for new users.

Systems, gates, and rage

AI 摘要This article presents the text of a PyCon US 2025 lightning talk arguing that LLMs, like Stack Overflow and animal farming, are messy but potentially useful tools whose harms should be addressed through system-level solutions rather than by blaming individual users. The author acknowledges legitimate concerns about LLMs, such as intellectual property, environmental impact, and job disruption, while noting these tools are not going away. Ultimately, the talk urges readers to reflect before criticizing whether they are gatekeeping, and to channel their frustration about new technologies into something more productive.

Python Morsels now has spaced repetition

AI 摘要Python Morsels has launched Daily Recall, a spaced repetition system for Python programmers that uses the FSRS algorithm to prompt users with quick recall questions just before they would forget the material. The system is built on the principle of active recall—retrieving information from memory rather than re-reading—which helps learners beat the forgetting curve with just a few minutes of daily practice. Most packs (covering topics like time complexity, uv, string methods, and f-strings) are free, with the rest included in the All Access plan, and early users reported retaining 25 to 50 new facts after their first month.

A Dolly Parton developer

AI 摘要The author, feeling both sad about Dolly Parton's passing and nostalgic while friends gather at DjangoCon US, reflects on Rikki Endsley's keynote about being a "Willie Nelson developer" and extends the concept by proposing a "Dolly Parton developer" mindset. They highlight three of Dolly's admirable traits—knowing your rights (refusing to give Elvis half the publishing to "I Will Always Love You"), exiting with grace (leaving the Porter Wagoner Show amicably), and prolifically writing the next song regardless of publication or success. The piece closes with an encouragement to developers to embody these values and keep creating.