Professional Python cover

Professional Python

No rating yet
Word count
412 words
Chapters
18
ISBN
9787302452850

Tags

Summary

Professional Python is one volume of the English-language bestseller series of the same name. The original Professional Python was written by veteran Python developer Luke Sneeringer, and the simplified Chinese edition was translated by Song Yunjian and Liu Lei and published by Tsinghua University Press in November 2016. The book does not start with variables and loops; it assumes readers can already write working Python scripts and focuses on the language mechanisms that everyday tutorials skip over but real projects use every day: how decorators take effect in order, why call signatures matter when decorators take arguments, how context managers behind the with statement clean up resources and handle exceptions, and how generators and iterators process—even infinite—data streams in slices. Part Two turns to classes and the object model: how magic methods take over operator overloading and type conversion, how type and metaclasses intervene at class creation, what kinds of runtime attribute problems class factories solve, and how abstract base classes use register and __subclasshook__ to declare "virtual subclasses" and protocols. Part Three tackles old data-layer problems: how Python 2 byte strings differ from Python 3 text strings, why non-ASCII characters and various encodings are not mutually compatible, and how to use regex grouping, lookahead, substitution, and precompilation. The final part leans toward engineering practice: differences and cross-version compatibility strategies between Python 2 and 3, unit testing and mocking, command-line tools optparse and argparse, and the then-new asyncio—event loops, coroutines, Futures and Tasks, callbacks, queues, and servers. The book uses "when to use it, when not to" as its thread, with runnable example code, helping readers organize scattered language features into maintainable architecture. The original was written around Python 3.5, so some material on version compatibility and async patterns is behind current practice; read it alongside current documentation.

Editor's review

很多 Python 书把“高级”理解为多讲几个库,这本书的思路不一样:它挑的是语言本身那些“会用但说不清”的机制,并且每讲一个都先回答“为什么需要它”,再回答“什么时候不该用它”。 装饰器一章从函数注册表讲起,逐步过渡到带参数的装饰器、装饰类与类型转换,把闭包、调用签名这些容易踩坑的地方讲透;上下文管理器一章把异常传播与异常抑制分开讨论,读完就知道自己写的 with 到底该不该吞掉异常;生成器一章连“生成器什么时候是单例”这种细节都没放过。类模型部分对元类、类工厂、抽象基类的处理尤其克制——作者反复提醒元类是把“大锤”,能用简单办法解决就别用。字符串与 Unicode 一章放在 Python 3 已经普及的今天仍然有价值,因为它解释的是编码问题的成因,而不是某个版本的记忆点。 全书篇幅不大,249 页,代码密度高,几乎没有凑字数的段落。适合作为“第二本 Python 书”,也适合放在手边,在写库、做重构、接手老项目时翻一翻。需要提醒的是,原书写成于 2016 年前后,Python 2/3 兼容、asyncio 早期 API 等章节已明显过时,这部分更适合当作历史背景读,具体写法请以当前官方文档为准。

Who it's for

A good fit for

  • 已经能用 Python 写脚本,想补齐装饰器、生成器、元类等进阶知识的中级开发者
  • 需要设计库、框架或重构老项目,想弄清语言机制边界的工程师
  • 被 Unicode 编码、Python 2/3 混用问题反复困扰的维护者
  • 想系统了解单元测试、命令行工具与异步编程基础用法的自学者

Not a good fit for

  • 完全没有 Python 基础、还在学语法与循环判断的初学者
  • 只想找现成案例做数据分析或机器学习的读者
  • 需要最新 Python 3.11 及以上异步与类型标注实践的读者

Reading tips

  1. 先读第1—3章并动手改写自己项目里的装饰器与生成器,再进入类模型部分,顺序阅读收益最大。
  2. 每章末尾的小结建议读两遍:第一遍理解概念,第二遍对照自己的代码,找出可以替换的写法。
  3. 第10章 Python 2 与 Python 3、第13章 asyncio 属时代性内容,重点理解设计动机,具体 API 以官方文档为准。
  4. 配合官方语言参考与标准库文档查阅,遇到版本差异时优先相信当前文档而非书中示例。

About the publisher

Tsinghua University Press China · Founded in 1980

Founded in 1980, Tsinghua University Press has 57 titles in our collection, covering popular science, medicine, health, law, philosophy and social sciences. Representative works include medical popular-science books such as Cancer Truth: Doctors Are Reading It Too and New Knowledge on Cancer by Bo Luo (Li Zhizhong), legal titles such as Sunshine Is the Best Preservative: Express Delivery of Major Global Anti-Corruption Cases, and works like Qi Ge's A Brief History of Philosophy with Big Ideas and Liu Yunhao's From the Internet to a New Industrial Revolution. Its authors include science writers, medical researchers, the Renmin University of China anti-corruption master's class and university scholars, reflecting a publishing profile that balances academic seriousness with accessible reading. As public information is limited, this profile is based only on the titles in our collection.

Contents

  1. Part I Functions
  2. Chapter 1 Decorators
  3. Chapter 2 Context Managers
  4. Chapter 3 Generators
  5. Part II Classes
  6. Chapter 4 Magic Methods
  7. Chapter 5 Metaclasses
  8. Chapter 6 Class Factories
  9. Chapter 7 Abstract Base Classes
  10. Part III Data
  11. Chapter 8 Strings and Unicode
  12. Chapter 9 Regular Expressions
  13. Part IV Other Topics
  14. Chapter 10 Python 2 and Python 3
  15. Chapter 11 Unit Testing
  16. Chapter 12 Command-Line Tools
  17. Chapter 13 asyncio
  18. Chapter 14 Code Style

FAQ

这本书适合零基础学 Python 吗?
不适合。原书序言明确面向已熟悉 Python 的读者,开篇直接讲装饰器与上下文管理器,没有变量、循环、函数定义等入门内容。零基础读者建议先完成一本入门教程并写过几个小项目,再来读这本。
这本书和 Michał Jaworski 的《Python高级编程(第2版)》是同一本吗?
不是。Jaworski 与 Tarek Ziadé 合著的那本英文名为 Expert Python Programming,中文版由人民邮电出版社出版,内容偏工程实践与打包发布;本书英文名为 Professional Python,作者是 Luke Sneeringer,由清华大学出版社出版。
书里的 Python 2 和 asyncio 内容现在还能用吗?
书稿成于 2016 年前后,Python 2 已于 2020 年停止维护,asyncio 的部分 API 此后也有调整。这些章节仍有理解价值——它们解释兼容问题与事件循环的设计动机——但具体写法请以当前 Python 官方文档为准。
需要什么基础才能读懂元类和抽象基类那几章?
需要熟悉类、继承、实例属性与类属性的区别,并且最好写过至少一个稍大的类结构。作者在第5、6章会从 type 与类创建过程讲起,但不会回头补面向对象基础语法。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category