In early February, I came across this tweet:
The author of Smooth Python has some exciting news: he’s writing a second edition!
If you were to vote for the best advanced Python book, this book would definitely be one of the top votes. I wanted to recommend it when I first wrote the Python Cat Book series, but I thought I’d save the good stuff for last, so I’ve been putting it off until now…
If you have read it, you will certainly recommend it; If not, read on to see if my introduction will convince you to make it a must-read
The book, Fluent Python, was published in August 2015. Two years later, Turing Education in China produced the translation, which was published in May 2017 and received a score of 9.4 on Douban. (It’s such a long process to translate/publish books.)
Luciano Ramalho is a Brazilian, veteran Python programmer/speaker and member of the Python Software Foundation (PSF). The book’s technical reviewers and referees include a wide range of people in the industry.
The book was well received in the circle, publishers of various countries have introduced copyright, at least nine language versions (to count how many do you know?) :
PS: The picture is from @FluentPython official tweet, simplified Chinese version is the thinnest, coincidence occupy C bit. According to Turing Education, the simplified Chinese version has sold more than 40,000 copies and is expected to surpass the English version by 2020.
So, what is this book about? What’s so special about it?
The book is full of contents, including preface, appendix and glossary, which can be divided into six parts and 21 chapters. I made a mind map of the core chapters:
(Reply “Fluent” on the Python cat account with full HD original image)
The above is the mind map of the main chapter. The numbers in the figure are the number of folded branches.
Here’s a look at some of the details:
The original image is too large to display. Reply “Fluent” in the Python Cat public account with full HD original, PDF and MarkDown versions
As you can see from the chapters, this book is aimed at mid-to-advanced developers. It barely touches on introductory content, focusing instead on topics such as data models, data structures, functional objects, object-oriented, control flow, and metaprogramming.
Opening chapter 1, the author implements a deck of cards by hand with a few dozen lines of Python code:
import collections
Card = collections.namedtuple('Card'['rank'.'suit'])
class FrenchDeck:
ranks = [str(n) for n in range(2.11)] + list('JQKA')
suits = 'spades diamonds clubs hearts'.split()
def __init__(self) :
self._cards = [Card(rank, suit) for suit in self.suits for rank in self.ranks]
def __len__(self) :
return len(self._cards)
def __getitem__(self, position) :
return self._cards[position]
Copy the code
Then it gets right to the core topic of the book: data models made up of special methods.
Special methods are named __xxx__() with double underlining, often referred to as magic methods and dunder methods, and are unique to Python.
The data model is undoubtedly a key core of the Python language, the cornerstone of what is known as pythonic. Everything in Python is an object, and the data model is the interface specification for those objects, which makes Python extremely consistent in its behavior.
Starting with the data model, Smooth Python sets the tone for the entire article, focusing on the construction of Python objects and the details of features within the language, with the goal of making code more idiomatic, concise, efficient, and easy to read.
The author of Smooth Python with the Chinese version
It then covers some of the features of Python’s built-in types (sequence types, map types, text, and byte types), functions as special objects and the use of general objects, and the flow of control (iterators, generators, context managers, coroutines, and concurrent programming), Finally, dive into the dark arts of metaprogramming (descriptors and metaclases).
Over 600 pages, the book is so full that you can’t stop feeling like you’re learning something new, and like, oh, I want to learn more.
Many students will have a read books say: “read/gossip” it is not idle, but some content is more wonderful than the body, the author showed his rich knowledge in this (the official document, community evolution of allusions, grammar, articles video, open source projects, language differences, etc.), each chapter is worth reading. No Python book currently comes close to matching it in this respect.
I recommend that you find chapters that interest you and read them. In addition, there are some very good reading notes (they are quite long) that I put here:
www.hongweipeng.com/index.php/a… (by hongweipeng)
Frankorz.com/2017/07/01/… (By Cat Winter)
The first version of Smooth Python was based on Python 3.4, which was the latest at the time. Over the years, Python has continued to enrich itself, both officially ending Python version 2 and rapidly evolving to the latest version 3.9.
However, because the author focuses on core Python concepts and explores features that are largely immutable, there is no need to worry too much about obsolescence, and it is still a highly recommended book to buy and read.
I am very concerned about the second edition, but I also know that writing takes time, and publishing in English, Chinese and Chinese takes time, so let’s wait and see.