Python 3 Object-oriented Programming - Second Edition
eBook - ePub

Python 3 Object-oriented Programming - Second Edition

Dusty Phillips

Partager le livre
  1. 460 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Python 3 Object-oriented Programming - Second Edition

Dusty Phillips

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

About This Book

  • Stop writing scripts and start architecting programs
  • Learn the latest Python syntax and libraries
  • A practical, hands-on tutorial that teaches you all about abstract design patterns and how to implement them in Python 3

Who This Book Is For

If you're new to object-oriented programming techniques, or if you have basic Python skills and wish to learn in depth when to correctly apply object-oriented programming in Python to design software, this is the book for you.

What You Will Learn

  • Implement objects in Python by creating classes and defining methods
  • Separate related objects into a taxonomy of classes and describe the properties and behaviors of those objects via the class interface
  • Extend class functionality by using inheritance
  • Understand when to use object-oriented features, and more importantly, when not to use them
  • Discover what design patterns are and why they are different in Python
  • Uncover the simplicity of unit testing and why it's so important in Python
  • Grasp common concurrency techniques and pitfalls in Python 3
  • Explore the new AsyncIO module for developing massively concurrent network systems

In Detail

Python 3 Object-oriented Programming, Second Edition, explains classes, data encapsulation, inheritance, polymorphism, abstraction, and exceptions with an emphasis on when you can use each principle to develop well-designed software. It will not only guide you to create maintainable applications by studying higher level design patterns but will also help you grasp the complexities of string and file manipulation, and how Python distinguishes between binary and textual data. As a bonus, you will also discover the joys of unit testing and the complexities of concurrent programming.

This book is packed with updated content to reflect recent changes to the core Python library that were not available when the highly rated first edition was originally published. It has also been restructured and reorganized to improve the flow of knowledge and enhance the reading experience.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Python 3 Object-oriented Programming - Second Edition est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Python 3 Object-oriented Programming - Second Edition par Dusty Phillips en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Object Oriented Programming. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2015
ISBN
9781784395957

Python 3 Object-oriented Programming Second Edition


Table of Contents

Python 3 Object-oriented Programming Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Introduction to the second edition
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Object-oriented Design
Introducing object-oriented
Objects and classes
Specifying attributes and behaviors
Data describes objects
Behaviors are actions
Hiding details and creating the public interface
Composition
Inheritance
Inheritance provides abstraction
Multiple inheritance
Case study
Exercises
Summary
2. Objects in Python
Creating Python classes
Adding attributes
Making it do something
Talking to yourself
More arguments
Initializing the object
Explaining yourself
Modules and packages
Organizing the modules
Absolute imports
Relative imports
Organizing module contents
Who can access my data?
Third-party libraries
Case study
Exercises
Summary
3. When Objects Are Alike
Basic inheritance
Extending built-ins
Overriding and super
Multiple inheritance
The diamond problem
Different sets of arguments
Polymorphism
Abstract base classes
Using an abstract base class
Creating an abstract base class
Demystifying the magic
Case study
Exercises
Summary
4. Expecting the Unexpected
Raising exceptions
Raising an exception
The effects of an exception
Handling exceptions
The exception hierarchy
Defining our own exceptions
Case study
Exercises
Summary
5. When to Use Object-oriented Programming
Treat objects as objects
Adding behavior to class data with properties
Properties in detail
Decorators – another way to create properties
Deciding when to use properties
Manager objects
Removing duplicate code
In practice
Case study
Exercises
Summary
6. Python Data Structures
Empty objects
Tuples and named tuples
Named tuples
Dictionaries
Dictionary use cases
Using defaultdict
Counter
Lists
Sorting lists
Sets
Extending built-ins
Queues
FIFO queues
LIFO queues
Priority queues
Case study
Exercises
Summary
7. Python Object-oriented Shortcuts
Python built-in functions
The len() function
Reversed
Enumerate
File I/O
Placing it in context
An alternative to method overloading
Default arguments
Variable argument lists
Unpacking arguments
Functions are objects too
Using functions as attributes
Callable objects
Case study
Exercises
Summary
8. Strings and Serialization
Strings
String manipulation
String formatting
Escaping braces
Keyword arguments
Container lookups
Object lookups
Making it look right
Strings are Unicode
Converting bytes to text
Converting text to bytes
Mutable byte strings
Regular expressions
Matching patterns
Matching a selection of characters
Escaping characters
Matching multiple characters
Grouping patterns together
Getting information from regular expressions
Making repeated regular expressions efficient
Serializing objects
Customizing pickles
Serializing web objects
Case study
Exercises
Summary
9. The Iterator Pattern
Design patterns in brief
Iterators
The iterator protocol
Comprehensions
List comprehensions
Set and dictionary comprehensions
Generator expressions
Generators
Yield items from another iterable
Coroutines
Back to log parsing
Closing coroutines and throwing exceptions
The relationship between coroutines, generators, and functions
Case study
Exercises
Summary
10. Python Design Patterns I
The decorator pattern
A decorator example
Decorators in Python
The observer pattern
An observer example
The strategy pattern
A strategy example
Strategy in Python
The state pattern
A state example
State versus strategy
State transition as coroutines
The singleton pattern
Singleton implementation
The template pattern
A template example
Exercises
Summary
11. Python Design Patterns II
The adapter pattern
The facade pattern
The flyweight pattern
The command pattern
The abstract factory pattern
The composite pattern
Exercises
Summary
12. Testing Object-oriented Programs
Why test?
Test-driven development
Unit testing
Assertion methods
Reducing boilerplate and cleaning up
Organizing and running tests
Ignoring broken tests
Testing with py.test
One way to do setup and cleanup
A completely different way to set up variables
Skipping tests with py.test
Imitating expensive objects
How much testing is enough?
Case study
Implementing it
Exercises
Summary
13. Concurrency
Threads
The many problems with threads
Shared memory
The global interpreter lock
Thread overhead
Multiprocessing
Multiprocessing pools
Queues
The problems with multiprocessing
Futures
AsyncIO
AsyncIO in action
Reading an AsyncIO future
AsyncIO for networking
Using executors to wrap blocking code
Streams
Executors
Case study
Exercises
Summary
Index

Python 3 Object-oriented Programming Second Edition

Copyright © 2015 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.
First published: July 2010
Second edition: August 2015
Production reference: 1130815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-878-1
www.packtpub.com

Credits

Author
Dusty Phillips
Reviewers
AMahdy AbdElAziz
Grigoriy Beziuk
Krishna Bharadwaj
Justin Cano
Anthony Petitbois
Claudio Rodriguez
Commissioning Editor
Edward Gordon
Acquisition Editors
Indrajit Das
Rebecca Pedley
Greg Wild
Content Development Editors
Divij Kotian
Arvind Koul
Anila Vincent
Technical Editor
Siddhi Rane
Copy Editor
Janbal Dharmaraj
Project Coordinator
Neha Bhatnagar
Proofreader
Safis Editing
Indexer
Hemangini Bari
Graphics
Sheetal Aute
Jason Monteiro
Production Coordinator
Komal Ramchandani
Cover Work
Komal Ramchandani

About the Author

Dusty Phillips is a Canadian software developer and author currently living in Seattle, Washington. He has been active in the open source community for a decade and a half and programming in Python for nearly all of it. He cofounded the popular Puget Sound Programming Python meetup group; drop by and say hi if you're in the area.
Python 3 Object Oriented Programming, Packt Publishing, was the first of his books. He has also written Creating Apps In Kivy, O'Reilly, the mobile Python library, and self-published Hacking Happy, a journey to mental wellness for the technically inclined. He was hospitalized for suicidal tendencies shortly after the first edition of this book was published and has been an outspoken proponent for positive mental health ever since.

About the Reviewers

AMahdy AbdElAziz has more than 8 years of experience in software engineering using several languages and frameworks. Over the last 5 years, he has focused on Android and mobile development, including cross-platform tools, and Android internals, such as building custom ROMs and customizing AOSP for embedded devices.
He is currently teaching Python at Information Technology Institution. You can visit his website, http://www.amahdy.net/, to find out more about him.
Grigoriy Beziuk is a former CIO of Crowdage Foundation, acting as an independent software developer as this book was being written. He has worked with a wide variety of programming languages and technologies, including different versions of Python in different environments, ranging from purely scientific ones to modern production-scale web development issues.

Table des matiĂšres