Professional Python

Professional Python
О книге

Master the secret tools every Python programmer needs to know

Professional Python goes beyond the basics to teach beginner- and intermediate-level Python programmers the little-known tools and constructs that build concise, maintainable code. Design better architecture and write easy-to-understand code using highly adoptable techniques that result in more robust and efficient applications. Coverage includes Decorators, Context Managers, Magic Methods, Class Factories, Metaclasses, Regular Expressions, and more, including advanced methods for unit testing using asyncio and CLI tools. Each topic includes an explanation of the concept and a discussion on applications, followed by hands-on tutorials based on real-world scenarios. The "Python 3 first" approach covers multiple current versions, while ensuring long-term relevance.

Python offers many tools and techniques for writing better code, but often confusing documentation leaves many programmers in the dark about how to use them. This book shines a light on these incredibly useful methods, giving you clear guidance toward building stronger applications.

Learn advanced Python functions, classes, and libraries

Utilize better development and testing tools

Understand the "what," "when," "why," and "how"

More than just theory or a recipe-style walk-through, this guide helps you learn – and understand – these little-known tools and techniques. You'll streamline your workflow while improving the quality of your output, producing more robust applications with cleaner code and stronger architecture. If you're ready to take your Python skills to the next level, Professional Python is the invaluable guide that will get you there.

Читать Professional Python онлайн беплатно


Шрифт
Интервал

Introduction

This book introduces the reader to more advanced Python programming by providing an intermediate course in the Python language.

Recently, Python has become more and more frequently the developer's language of choice. It is used all over the world, for myriad purposes. As adoption continues to increase, more and more developers are spending their days writing Python.

Python has grown so steadily precisely because it is a very powerful language, and even many seasoned Python developers have only scratched the surface of what the language is capable of doing.

Who This Book Is For

This book is for developers who have already worked in Python, are already familiar with the language, and desire to learn more about it. This book assumes that readers have already done most basic tasks involved with developing in Python (such as having used the Python interactive terminal).

If you are a reader who seeks a general survey of intermediate to advanced Python language features, you should read this book from start to finish.

Alternatively, you may be a reader who has used some more-advanced language features in passing, or potentially needs to maintain code that uses such features. Consider using this book as a reference guide or index to flesh out your understanding when you are grappling with a particular implementation.

What This Book Covers

This book covers all recent versions of Python (including both Python 2 and Python 3). At the time of this writing, the most recent version available is Python 3.4, and Python 3.5 is in beta. This book primarily covers Python 2.6, 2.7, 3.3, and 3.4. Most code is provided in a manner that will run on both Python 2 and Python 3, with Python 2 code specifically noted as such.

Additionally, this book includes a chapter with a deep dive into distinctions between Python 2 and Python 3, which provides advice on writing code to run on multiple versions of Python, as well as porting over to Python 3.

This book primarily focuses on two areas. The first is features of the language itself. For example, this book includes several chapters about various aspects of how Python's class and object model works. The second area is modules provided as part of the standard library. For example, this book includes a chapter each on modules such as >asyncio, >unittest, and >argparse.

How This Book Is Structured

This book is essentially divided into four parts.

The first three chapters in the book are fundamentally about functions in Python. This part includes a chapter each on decorators and context managers, which are reusable ways to modify or wrap functions to add functionality. It also includes a chapter on generators, which are a way to design functions that yield values one at a time, rather than creating an entire list of values in advance and returning them in one block.

The second part comprises the next four chapters, and they are all related somehow to Python classes and the language's object model. There is a chapter on magic methods. Then, there is a chapter each on metaclasses and class factories, which are two approaches to constructing classes in powerful ways. Finally, a chapter on abstract base classes explains the >abc module and how to make classes declare patterns that they implement.

The third part comprises two chapters about strings and data. There is a chapter on how to navigate using Unicode strings (as opposed to byte strings) in Python, which also covers in detail how strings differ between Python 2 and Python 3. There is also a chapter on regular expressions, which covers the Python >re module as well as how to write regular expressions.

Finally, the fourth part covers everything that does not neatly fit into one of the first three parts. This part begins with an in-depth look at the distinctions between Python 2 and Python 3, and how to write code that is interoperable with both. There is a chapter on unit testing, focusing on the >unittest module. A chapter on command-line interface (CLI) tools teaches you about both >optparse and >argparse, which are Python's modules for writing command-line tools. There is a chapter on >asyncio, which is a new asynchronous programming library that was added to the standard library in Python 3.4. Finally, the book closes with a chapter on style.

What You Need to Use This Book

You will, first and foremost, need a machine running Python.

Although it does not make a difference in most chapters, this book is slightly Linux-focused in its approach (this will be most relevant in the chapter on CLI tools). Examples were run in a Linux environment, and output may vary slightly on Windows.

Conventions

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

Warning

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Note

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:



Вам будет интересно