Mastering Object-oriented Python

Mastering Object-oriented Python

Language: English

Pages: 634

ISBN: 1783280972

Format: PDF / Kindle (mobi) / ePub

Key Features

  • Create applications with flexible logging, powerful configuration and command-line options, automated unit tests, and good documentation
  • Use the Python special methods to integrate seamlessly with built-in features and the standard library
  • Design classes to support object persistence in JSON, YAML, Pickle, CSV, XML, Shelve, and SQL

Book Description

An object-oriented approach to Python web development gives you a much more fully-realised experience of the language. The flexibility and power of Python, combined with the improvements in design, coding and software maintenance that object-oriented programming allows, is built to respond to the challenges of increasingly more complex and data-intensive application development, making difficult tasks much more manageable. This book has been designed to make this sophisticated approach to programming easier to learn quickly, providing you with a clear and coherent learning journey.

Beginning by looking at a range of design patterns for the _init_() method, you will learn how to effectively use a range of Python s special methods to create classes that integrate with Python s built-in features, and find detailed explorations and demonstrations of callables and contexts, containers and collections, numbers, and decorators and mixins, with a focus on best practices for effective and successful design. The book also features information that demonstrates how to create persistent objects using JSON, YAML, Pickle, CSV, XML, Shelve and SQL and shows you how to transmit objects between processes. Going further into OOP, you ll find expert information on logging, warnings, unit testing as well as working with the command line.

Structured in 3 parts to make the complexity of OOP more manageable - Pythonic Classes via Special Methods, Persistence and Serialization and Testing, Debugging, Deploying, and Maintaining this book offers deep insight into OOP that will help you develop expert level object-oriented Python skills.

What you will learn

  • Create applications with flexible logging, powerful configuration and command-line options, automated unit tests, and good documentation
  • Get to grips with different design patterns for the __init__() method
  • Design callable objects and context managers
  • Perform object serialization in formats such as JSON, YAML, Pickle, CSV, and XML
  • Map Python objects to a SQL database using the built-in SQLite module
  • Transmit Python objects via RESTful web services
  • Devise strategies for automated unit testing, including how to use the doctest and the unittest.mock module
  • Parse command-line arguments and integrate this with configuration files and environment variables

About the Author

Steven F. Lott has been programming since the 70s, 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. He's been using Python to solve business problems for over 10 years.

Table of Contents

  1. The _init_() Method
  2. Integrating Seamlessly with Basic Python Special Methods
  3. Attribute Access, Properties, and Descriptors
  4. The ABCs of Consistent Design
  5. Using Callables and Contexts
  6. Creating Contrainers and Collections
  7. Creating Numbers
  8. Decorators and Mixins: Cross-Cutting Aspects
  9. Serializing and Saving JSON, YAML, Pickle, CSV, and XML
  10. Storing and Retrieving Objects via Shelve
  11. Storing and Retrieving Objects via SQLite
  12. Transmitting and Sharing Objects
  13. Configuration Files and Persistence
  14. The Logging and Warning Modules
  15. Designing for Testability
  16. Coping with the Command Line

Office 2013 Simplified

Visualizing Time: Designing Graphical Representations for Statistical Data

Penetration Testing: A Hands-On Introduction to Hacking

Computing: A Concise History (The MIT Press Essential Knowledge Series)

Cisco Routers for the Desperate: Router and Switch Management, the Easy Way (2nd Edition)














following is an approach to override __str__() and __repr__() when there's no collection involved. These methods belong to the Card class, defined previously: def __repr__( self ): return "{__class__.__name__}(suit={suit!r}, rank={rank!r})". format( __class__=self.__class__, **self.__dict__) def __str__( self ): return "{rank}{suit}".format(**self.__dict__) These two methods rely on passing the object's internal instance variable dictionary, __dict__, to the format() function. This isn't

Handling containers and complex classes Dumping and loading multiple row types in a CSV file Filtering CSV rows with an iterator Dumping and loading joined rows in a CSV file Dumping and loading with XML Dumping objects using string templates Dumping objects with xml.etree.ElementTree Loading XML documents [ vi ] 251 253 254 255 255 258 260 262 263 265 266 266 268 269 270 271 272 275 276 277 279 280 281 282 283 284 286 287 290 291 293 294 Table of Contents Summary 295 Design

expression, object.attribute on the left-hand side of assignment, and object.attribute in a del statement. • Callables: A special method implements what we see as a function applied to arguments, much like the built-in len() function. • Collections: These special methods implement the numerous features of collections. This involves things such as sequence[index], mapping[key], and set | set. • Numbers: These special methods provide the arithmetic operators and the comparison operators. We can

return math.sqrt( n*sum(x**2 for x in outcomes)sum(outcomes)**2 )/n Both of these are relatively simple calculation functions that are easy to use. As things get more complex, however, loose functions like these become less helpful. One of the benefits of object-oriented programming is to bind the functionality with the data. Our first example will not involve rewriting any of the special methods of list. We'll simply subclass list to add methods that will compute the statistics. This is a very

the text like this: "We use this feature to update the label to a new random value every time we click on the Roll! button". Warnings or important notes appear in a box like this. Tips and tricks appear like this. Reader feedback Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback, simply send an e-mail

Download sample