This book is one of its own kind. It is not an encyclopedia or a hands-on tutorial that traps readers in the tutorial hell. It is a distillation of just one common Python user’s learning experience. The experience is packaged with exceptional teaching techniques, careful dependence unraveling and, most importantly, passion.
Learning Advanced Python by Studying Open Source Projects helps readers overcome the difficulty in their day-to-day tasks and seek insights from solutions in famous open source projects. Different from a technical manual, this book mixes the technical knowledge, real-world applications and more theoretical content, providing readers with a practical and engaging approach to learning Python.
Throughout this book, readers will learn how to write Python code that is efficient, readable and maintainable, covering key topics such as data structures, algorithms, object-oriented programming and more. The author’s passion for Python shines through in this book, making it an enjoyable and inspiring read for both beginners and experienced programmers.
Learning Advanced Python by Studying Open Source Projects is a book that is written for 95% of Python users, covering 95% of their daily use cases. What does this mean? From the content perspective, it means that this book is not an encyclopedia that covers everything. It covers all the important things for most Python users. Based on my observations and research, the following topics are considered important:
1. The Python data model
2. The Python classes
3. Concurrency and asynchronous programming
4. Functions and related tips
5. How to design an OOP system
6. How to test code
Author(s): Rongpeng Li
Series: The Python Series
Publisher: CRC Press LLC
Year: 2023
Language: English
Pages: 139
Preface
Acknowledgments
INTRODUCTION
PURPOSE AND SCOPE OF THIS BOOK
OVERVIEW OF THE APPROACH TAKEN
NOTE
CHAPTER 1 ◾ The Data Model of Python
A GENTLE INTRODUCTION TO PYTHON’S DATA MODEL
CUSTOMIZED COMPARISON
A MANAGED ITERATION BEHAVIOR
ATTRIBUTES, FUNCTION OR DICTIONARY?
SUMMARY
NOTES
CHAPTER 2 ◾ Selected Topics of Python Classes
INTRODUCTION
DESCRIPTORS AND ATTRIBUTE LOOKUP ORDER
Descriptor Demystified
Lazy Evaluation in Matplotlib
METACLASS AND ITS USAGE IN ELASTICSEARCH DSL
Understanding Metaclass Using Meta-Recipe
Use Metaclass to Model Documents in Elasticsearch DSL
SUMMARY
APPENDIX
NOTES
CHAPTER 3 ◾ Concurrency in Python
CONCURRENCY FROM A TOP-DOWN PERSPECTIVE
Operating System and Concurrency
Introducing Global Interpreter Lock (GIL)
MULTIPROCESSING FOR CPU BOUND TASKS
Parallel Pandas Apply in pandarallel
MULTITHREADING FOR I/O BOUND TASKS
SUMMARY
NOTES
CHAPTER 4 ◾ Asynchronous Programming in Python
A SHIFT OF PARADIGM
EVENT-DRIVEN SIMULATION
ASYNC AS A PATTERN
SUMMARY
APPENDIX
NOTES
CHAPTER 5 ◾ Power Up Your Python Functions
INTRODUCTION
THE DECORATOR FOR RETRYING A FUNCTION
CONTEXT MANAGER IN A NUTSHELL
DIVE INTO THE AIOSQLITE EXAMPLE
Connection as an Executor and a Scheduler
Connection and Cursor as Async Context Managers
SUMMARY
NOTES
CHAPTER 6 ◾ Selected OOP Design Best Practices
UNDERSTAND YOUR BUSINESS
A Quick Overview of the Business
MODEL THE BUSINESS ENTITIES WITH OOP
Design the Core Entities
Establish the Relationship between Classes
The Benefits of Universal interface
Sometimes No OOP is the Best Design
SUMMARY
NOTES
CHAPTER 7 ◾ Testing in a Pistachio Shell
INTRODUCTION
FIXTURE AND PARAMETERIZATION
Parameterization
Resources and Fixture
MONKEY PATCH
Modify the Built-in Print
More Powerful Monkey Patching
PROPERTY-BASED TEST
SUMMARY
NOTES
INDEX