<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python Engineering on Chen Kai Blog</title><link>https://www.chenk.top/zh/categories/python-engineering/</link><description>Recent content in Python Engineering on Chen Kai Blog</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Wed, 27 Apr 2022 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/zh/categories/python-engineering/index.xml" rel="self" type="application/rss+xml"/><item><title>Python 工程实践（八）：性能优化 —— 性能分析、缓存与适时收手</title><link>https://www.chenk.top/zh/python-engineering/08-performance-and-profiling/</link><pubDate>Wed, 27 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/08-performance-and-profiling/</guid><description>&lt;p>Donald Knuth 那句广为流传的名言常被断章取义。完整原文是：“我们应当忽略微小的效率提升，比如 97% 的情况：过早优化是一切罪恶之源。然而，我们也不应放过那至关重要的 3% 中的良机。”后半句恰恰是重点所在——性能优化并非追求“一切皆快”，而是精准识别真正影响全局的那 3%，并集中资源将其优化。&lt;/p></description></item><item><title>Python 工程实践（七）：打包分发 —— 从 pip install 到 PyPI</title><link>https://www.chenk.top/zh/python-engineering/07-packaging-and-distribution/</link><pubDate>Sun, 24 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/07-packaging-and-distribution/</guid><description>&lt;p>你写了一个实用的小工具，同事找你要。你把文件夹打包成 ZIP 发过去，对方解压后运行 &lt;code>python main.py&lt;/code>，却报了 &lt;code>ModuleNotFoundError&lt;/code> —— 因为缺少依赖。他手动装上依赖，结果版本不对；更糟的是，他用的是 Python 3.8，而你的代码里用了 f-string 中的海象运算符（walrus operator），这在 3.8 里根本跑不了。&lt;/p></description></item><item><title>Python 工程实践（六）：并发编程 —— 线程、进程与 asyncio</title><link>https://www.chenk.top/zh/python-engineering/06-concurrency/</link><pubDate>Thu, 21 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/06-concurrency/</guid><description>&lt;p>你的脚本一次只下载 100 个文件，每个约耗时 2 秒——绝大部分时间在等待服务器响应，总耗时 200 秒，而 CPU 99% 的时间处于空闲状态。你为网络延迟付费，却白白浪费了计算资源，并发编程正是为了解决这个问题而诞生的。&lt;/p></description></item><item><title>Python 工程实践（五）：I/O、序列化与数据格式</title><link>https://www.chenk.top/zh/python-engineering/05-io-and-serialization/</link><pubDate>Tue, 19 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/05-io-and-serialization/</guid><description>&lt;p>大多数程序本质上只是在不同数据格式之间搭管道：读一个 CSV，转换一下，写成 JSON；加载配置文件，校验后传给应用。每个 Python 开发者都写过这类代码，而其中大多数人至少踩过一次编码、路径处理或序列化细节的坑。&lt;/p></description></item><item><title>Python 工程实践（四）：类型提示、代码检查与质量保障</title><link>https://www.chenk.top/zh/python-engineering/04-type-hints-and-linting/</link><pubDate>Sun, 17 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/04-type-hints-and-linting/</guid><description>&lt;p>代码评审应聚焦于逻辑与架构设计，而不是纠结于单引号还是双引号——这类争论纯粹是浪费工程师的时间。解决方案很简单：让机器处理代码风格，让人专注于逻辑正确性。&lt;/p></description></item><item><title>Python 工程实践（三）：测试——pytest、Fixture 与信心循环</title><link>https://www.chenk.top/zh/python-engineering/03-testing-and-debugging/</link><pubDate>Thu, 14 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/03-testing-and-debugging/</guid><description>&lt;p>你只改了一行代码，却导致三个毫不相干的功能崩溃；重构一个函数后，不得不花上两小时手动点击整个应用，只为确认一切是否还正常；周五部署上线，结果半夜就被报警电话叫醒……所有这些，都是同一种病的症状：&lt;strong>没有测试&lt;/strong>。&lt;/p></description></item><item><title>Python 工程实践（二）：项目结构 —— 从脚本到包</title><link>https://www.chenk.top/zh/python-engineering/02-project-structure/</link><pubDate>Tue, 12 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/02-project-structure/</guid><description>&lt;p>每个项目都始于单个文件。你写下 &lt;code>main.py&lt;/code>，它能运行；接着不断添加功能，直到某天猛然发现：这个文件已经膨胀到 1500 行，函数层层嵌套，彼此调用，而它们依赖的全局变量却定义在 800 行开外。代码虽然能跑，但没人（包括未来的你）看得懂。&lt;/p></description></item><item><title>Python 工程实践（一）：环境搭建——pyenv、venv 与依赖地狱</title><link>https://www.chenk.top/zh/python-engineering/01-environment-and-toolchain/</link><pubDate>Sun, 10 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/01-environment-and-toolchain/</guid><description>&lt;p>每位 Python 开发者都经历过这样的时刻：你在同事的机器上运行一段脚本，结果却崩溃了——因为对方用的是 Python 3.8，而你是在 3.11 上写的。更糟的是，你执行了 &lt;code>pip install&lt;/code> 全局安装某个包，结果意外破坏了一个完全无关的项目。Python 的环境管理体系一旦掌握，其实非常强大，但默认体验却像一片布满地雷的雷区。&lt;/p></description></item></channel></rss>