Skip to main content
main-content
Top

About this book

Refine your programming techniques and approaches to become a more productive and creative Python programmer. This book explores the concepts and features that will improve not only your code but also your understanding of the Python community with insights and details about the Python philosophy.

Pro Python 3, Third Edition gives you the tools to write clean, innovative code. It starts with a review of some core Python principles, which are illustrated by various concepts and examples later in the book. The first half of the book explores aspects of functions, classes, protocols, and strings, describing techniques which may not be common knowledge, but which together form a solid foundation. Later chapters cover documentation, testing, and app distribution. Along the way, you’ll develop a complex Python framework that incorporates ideas learned throughout the book.

Updates in this edition include the role of iterators in Python 3, web scraping with Scrapy and BeautifulSoup, using Requests to call web pages without strings, new tools for distribution and installation, and much more. By the end of the book you'll be ready to deploy uncommon features that can take your skills to the next level in Python.

What You’ll Learn

Implement programs with various types of Python functions

Work with classes and object-oriented programmingUse strings from the standard library and third-party librariesHarvest web site data with PythonAutomate unit testing by writing a test suiteReview imaging, random number generation, and NumPy scientific extensionsUnderstand The Zen of Python documentation to help you decide the best way to distribute your code

Who This Book Is For

Intermediate programmers familiar with Python who are looking to move to an advanced level. You should have written at least a simple Python application, and be comfortable with a basic object-oriented approach, using the interactive interpreter, and writing control structures.

Table of Contents

Chapter 1. Principles and Philosophy

Abstract
Over 350 years ago, the famous Japanese swordsman Miyamoto Musashi wrote The Book of Five Rings about what he learned from fighting and winning over 60 duels between the ages of 13 and 29. His book might be related to a Zen Buddhist martial arts instruction book for sword fighting. In the text, which originally was a five-part letter written to the students at the martial arts school he founded, Musashi outlines general thoughts, ideals, and philosophical principles to lead his students to success.
J. Burton Browning, Marty Alchin

Chapter 2. Advanced Basics

Abstract
Like any other book on programming, the remainder of this book relies on quite a few features that may or may not be considered commonplace by readers. You, the reader, are expected to know a good deal about Python and programming in general, but there are a variety of lesser-used features that are extremely useful in the operations of many techniques shown throughout the book.
J. Burton Browning, Marty Alchin

Chapter 3. Functions

Abstract
At the core of any programming language is the notion of functions, but we tend to take them for granted. Sure, there’s the obvious fact that functions allow code to be encapsulated into individual units, which can be reused rather than being duplicated all over the place. But Python takes this beyond just the notion of what some languages allow, with functions being full-fledged objects that can be passed around in data structures, wrapped in other functions, or replaced entirely by new implementations.
J. Burton Browning, Marty Alchin

Chapter 4. Classes

Abstract
In Chapter 3 you reviewed how functions allow you to define code that can be reused. This allowed for general code streamlining by not having to retype "chunks" of code. However, it’s often more useful to combine those same functions into logical groupings that define the behavior and attributes of a particular type of object. This is standard object-oriented (OO) programming, which is implemented in Python by way of types and classes. These, like functions, may seem simple enough on the surface, but there’s a considerable amount of power behind them that you can leverage.
J. Burton Browning, Marty Alchin

Chapter 5. Common Protocols

Abstract
Most of the time, you’ll want to define objects that are highly customized to the needs of your application. This often means coming up with your own interfaces and APIs that are unique to your own code. The flexibility to do this is essential to the expansion capabilities of any system, but there is a price. Everything new that you invent must be documented and understood by those who need to use it.
J. Burton Browning, Marty Alchin

Chapter 6. Object Management

Abstract
Creating an instance of a class is only the beginning; once you have an object, there are a number of things you can do with it. This is obvious, of course, because objects have methods and attributes that are intended to control their behavior, but those are defined by each class. Objects, as a whole, have an additional set of features that allow you to manage them in a number of different ways.
J. Burton Browning, Marty Alchin

Chapter 7. Strings

Abstract
Given the fundamental nature of strings in all forms of programming, it should come as no surprise that Python’s string features can fill an entire chapter. Whether it’s interacting with users by way of keyboard input, sending content over the Web, analyzing big data, or participating in a Turing test, strings can and are used for many applications.
J. Burton Browning, Marty Alchin

Chapter 8. Documentation

Abstract
Documentation is arguably the most difficult part of any project. Code tends to come fairly easy to programmers, but documentation requires a different set of skills because the audience is strictly human. The magnitude of the differences can vary greatly between projects and audiences. Sometimes all that’s necessary is some example code, whereas other topics can fill entire books and still have plenty left to cover.
J. Burton Browning, Marty Alchin

Chapter 9. Testing

Abstract
Writing an application is only part of the process; it’s also important to check that all of the code works as it should. You can visually inspect the code, but it’s better to execute it in a variety of situations that may arise in the real world to make sure it behaves properly. This process is called unit testing, because the goal is to test the smallest available units of execution.
J. Burton Browning, Marty Alchin

Chapter 10. Distribution

Abstract
Once you have a working application, the next step is to decide how and where to distribute it. You might be writing it for yourself, but most likely you will have a wider audience and have a set schedule for releasing it. There are a number of decisions to be made and tasks to be performed before you can do that, however. This process consists primarily of packaging and distribution, but it begins with licensing.
J. Burton Browning, Marty Alchin

Chapter 11. Sheets: A CSV Framework

Abstract
Of course, the most important thing in programming is the program. Tools, techniques, philosophy, and advice don’t offer much at all if they’re never applied to solve a real-world problem. Sometimes that problem is very specific, but other times it’s merely a specific example of a more general problem. These general problems are typically the subject of libraries and frameworks, which can provide the base for a more specific application.
J. Burton Browning, Marty Alchin
Additional information