Python 3 Object Oriented Programming
eBook - ePub

Python 3 Object Oriented Programming

Dusty Phillips

Compartir libro
  1. 404 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Python 3 Object Oriented Programming

Dusty Phillips

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

In Detail

Object Oriented Programming is a very important aspect of modern programming languages. The basic principles of Object Oriented Programming are relatively easy to learn. Putting them together into working designs can be challenging.

This book makes programming more of a pleasure than a chore using powerful Python 3 object-oriented features of Python 3. It clearly demonstrates the core OOP principles and how to correctly implement OOP in Python.

Object Oriented Programming ranks high in importance among the many models Python supports. Yet, many programmers never bother learning the powerful features that make this language object oriented.

The book teaches when and how OOP should be correctly applied. It emphasizes not only the simple syntax of OOP in Python, but also how to combine these objects into well-designed software.

This book will introduce you to the terminology of the object-oriented paradigm, focusing on object-oriented design with step-by-step examples. It will take you from simple inheritance, one of the most useful tools in the object-oriented programmer's toolbox, all the way through to cooperative inheritance, one of the most complicated. You will be able to raise, handle, define, and manipulate exceptions.

You will be able to integrate the object-oriented and the not-so-object-oriented aspects of Python. You will also be able to create maintainable applications by studying higher level design patterns. You'll learn the complexities of string and file manipulation, and how Python distinguishes between binary and textual data. Not one, but two very powerful automated testing systems will be introduced to you. You'll understand the joy of unit testing and just how easy they are to create. You'll even study higher level libraries such as database connectors and GUI toolkits and how they apply object-oriented principles.

Harness the power of Python 3 objects; it's not just a scripting language

Approach

The book begins with the very foundations of OOP and then uses practical examples to show how to correctly implement Object Oriented Programming in Python. Many examples are taken from real-world projects. The book focuses on high-level design as well as the gritty details of the Python syntax. The provided exercises inspire the reader to think about his or her own code, rather than providing solved problems.

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 how and when to correctly apply Object Oriented Programming in Python, this is the book for you.

If you are an object-oriented programmer for other languages, you too will find this book a useful introduction to Python, as it uses terminology you are already familiar with.

Python 2 programmers seeking a leg up in the new world of Python 3 will also find the book beneficial, and you need not necessarily know Python 2.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Python 3 Object Oriented Programming un PDF/ePUB en línea?
Sí, puedes acceder a Python 3 Object Oriented Programming de Dusty Phillips en formato PDF o ePUB, así como a otros libros populares de Computer Science y Programming in Python. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2010
ISBN
9781849511261
Edición
1

Python 3 Object Oriented Programming


Table of Contents

Python 3 Object Oriented Programming
Credits
About the Author
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Object-oriented Design
Object-oriented?
Objects and classes
Specifying attributes and behaviors
Data describes objects
Behaviors are actions
Hiding details and creating the public interface
Composition and inheritance
Inheritance
Inheritance provides abstraction
Multiple inheritance
Case study
Exercises
Summary
2. Objects in Python
Creating Python classes
Adding attributes
Making it do something
Initializing the object
Explaining yourself
Modules and packages
Organizing the modules
Absolute imports
Relative imports
Who can access my data?
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
Case study
Exercises
Summary
4. Expecting the Unexpected
Raising exceptions
Raising an exception
What happens when an exception occurs?
Handling exceptions
Exception hierarchy
Defining our own exceptions
Exceptions aren't exceptional
Case study
Exercises
Summary
5. When to Use Object-oriented Programming
Treat objects as objects
Using properties to add behavior to class data
How it works
Decorators: another way to create properties
When should we use properties?
Managing objects
Removing duplicate code
In practice
Or we can use composition
Case study
Exercises
Summary
6. Python Data Structures
Empty objects
Tuples and named tuples
Named tuples
Dictionaries
When should we use dictionaries?
Using defaultdict
Lists
Sorting lists
Sets
Extending built-ins
Case study
Exercises
Summary
7. Python Object-oriented Shortcuts
Python built-in functions
Len
Reversed
Enumerate
Zip
Other functions
Comprehensions
List comprehensions
Set and dictionary comprehensions
Generator expressions
Generators
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. Python Design Patterns I
Design patterns
Decorator pattern
Decorator example
Decorators in Python
Observer pattern
Observer example
Strategy pattern
Strategy example
Strategy in Python
State pattern
State example
State versus strategy
Singleton pattern
Singleton implementation
Module variables can mimic singletons
Template pattern
Template example
Exercises
Summary
9. Python Design Patterns II
Adapter pattern
Facade pattern
Flyweight pattern
Command pattern
Abstract factory pattern
Composite pattern
Exercises
Summary
10. Files and Strings
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
File IO
Placing it in context
Faking files
Storing objects
Customizing pickles
Serializing web objects
Exercises
Summary
11. Testing Object-oriented Programs
Why test?
Test-driven development
Unit testing
Assertion methods
Additional assertion methods in Python 3.1
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
Test skipping with py.test
py.test extras
How much testing is enough?
Case Study
Implementing it
Exercises
Summary
12. Common Python 3 Libraries
Database access
Introducing SQLAlchemy
Adding and querying objects
SQL Expression Language
Pretty user interfaces
TkInter
PyQt
Choosing a GUI toolkit
XML
ElementTree
Constructing XML documents
lxml
CherryPy
A full web stack?
Jinja Templating
The CherryPy blog web application
Exercises
Summary
Index

Python 3 Object Oriented Programming

Copyright © 2010 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
Production Reference: 1160710
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849511-26-1
www.packtpub.com
Cover Image by Asher Wishkerman ()

Credits

Author
Dusty Phillips
Reviewers
Jason Chu
Michael Driscoll
Dan McGee
Lawrence Oluyede
Acquisition Editor
Steven Wilding
Development Editor
Mayuri Kokate
Technical Editor
Vanjeet D'souza
Indexer
Hemangini Bari
Editorial Team Leader
Mithun Sehgal
Project Team Leader
Lata Basantani
Project Coordinator
Jovita Pinto
Proofreader
Chris Smith
Graphics
Geetanjali Sawant
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade

About the Author

Dusty Phillips is a Canadian freelance software developer, teacher, martial artist, and open source aficionado. He is closely affiliated with the Arch Linux community and other open source projects. He maintains the Arch Linux storefronts, and compiled the popular Arch Linux Handbook. Dusty holds a Master's degree in Computer Science specializing in Human-Computer Interaction. He currently has six different Python interpreters installed on his computer.

About the Reviewers

Jason Chu is the CTO and part founder of Oprius Software Inc. He's developed software professionally for over 8 years. Chu started using Python in 2003 with version 2.2. When not developing personal or professional software, he spends his time teaching karate, playing go, and having fun in his hometown: Victoria, BC, Canada. You'll often find him out drinking the Back Hand of God Stout at Christie's Carriage House.
Michael Driscoll has been programming Python for almost 4 years and has dabbled in other languages since the late nineties. He graduated from university with a Bachelor's degree in Science, majoring in Management Information Systems. Michael enjoys programming for fun and profit. His hobbies include biblical apologetics, blogging about Python at http://www.blog.pythonlibrary.org/, and learning photography. Michael currently works for the local government where he programs with Python as much as possible. This is his first book as a technical reviewer.

Índice