Mastering Object-Oriented Python
Second Edition
Build powerful applications with reusable code using OOP design patterns and Python 3.7
Steven F. Lott
BIRMINGHAM - MUMBAI
Mastering Object-Oriented PythonSecond Edition
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Chaitanya Nair
Content Development Editor: Zeeyan Pinheiro
Senior Editor: Afshaan Khan
Technical Editor: Ketan Kamble
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Manju Arasan
Production Designer: Jayalaxmi Raja
First published: April 2014
Second edition: June 2019
Production reference: 1130619
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78953-136-7
www.packtpub.com
Packt.com
Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Fully searchable for easy access to vital information
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Steven F. Lott has been programming since the 1970s, when computers were large, expensive, and rare. As a contract software developer and architect, he has worked on hundreds of projects, from very small to very large ones. He's been using Python to solve business problems for over 10 years. His other titles with Packt include Python Essentials, Mastering Object-Oriented Python, Functional Python Programming Second Edition, Python for Secret Agents, and Python for Secret Agents II. Steven is currently a technomad who lives in various places on the East Coast of the US. You can follow him on Twitter via the handle @s_lott.
About the reviewers
Cody Jackson is a disabled military veteran, the founder of Socius Consulting an IT and business management consulting company in San Antonio and a cofounder of Top Men Technologies. He is currently employed at CACI International as the lead ICS/SCADA modeling and simulations engineer. He has been involved in the tech industry since 1994, when he joined the Navy as a nuclear chemist and Radcon Technician. Prior to CACI, he worked at ECPI University as a computer information systems adjunct professor. A self-taught Python programmer, he is the author of Learning to Program Using Python and Secret Recipes of the Python Ninja. He holds an Associate in Science degree, a Bachelor of Science degree, and a Master of Science degree.
Hugo Solis is an assistant professor in the Physics Department at the University of Costa Rica. His current research interests are computational cosmology, complexity, cryptography, and the influence of hydrogen on material properties. He has vast experience with languages, including C/C++ and Python for scientific programming. He is a member of the Free Software Foundation and has contributed code to some free software projects. He has also been a technical reviewer for Hands-On Qt for Python Developers and Learning Object-Oriented Programming, and he is the author of the Kivy Cookbook from Packt Publishing. Currently, he is in charge of the IFT, a Costa Rican scientific nonprofit organization for the multidisciplinary practice of physics.
I'd like to thank Katty Sanchez, my beloved mother, for her support and vanguard thoughts.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
This book will introduce you to many advanced features of the Python programming language. The focus is on creating the highest quality Python programs possible. This requires exploring design alternatives and determining which design offers the best performance while still being a good fit for the problem that is being solved.
The majority of this book showcases a number of alternatives for a given design. Some will offer better performance, while some will appear simpler or be a better solution to the problem domain. It's essential to locate the best algorithms alongside optimal data structures in order to create the most value with the least computer processing. Time is money, and programs that save time will create more value for their users. Python makes a number of internal features directly available to our application programs. This means that our programs can be very tightly integrated with existing Python features. We can leverage numerous Python features by ensuring that our object-oriented designs (OODs) integrate well.
As we explore different algorithms and data structures, we'll discover different memory and performance alternatives. It's an important OOD skill to be able to work through alternate solutions in order to properly optimize the final application. One of the more important themes of this book is that there's no single best approach to any problem.
Next page