Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Object-Oriented Programming - Fourth Edition

You're reading from  Python Object-Oriented Programming - Fourth Edition

Product type Book
Published in Jul 2021
Publisher Packt
ISBN-13 9781801077262
Pages 714 pages
Edition 4th Edition
Languages
Authors (2):
Steven F. Lott Steven F. Lott
Profile icon Steven F. Lott
Dusty Phillips Dusty Phillips
Profile icon Dusty Phillips
View More author details

Table of Contents (17) Chapters

Preface 1. Object-Oriented Design 2. Objects in Python 3. When Objects Are Alike 4. Expecting the Unexpected 5. When to Use Object-Oriented Programming 6. Abstract Base Classes and Operator Overloading 7. Python Data Structures 8. The Intersection of Object-Oriented and Functional Programming 9. Strings, Serialization, and File Paths 10. The Iterator Pattern 11. Common Design Patterns 12. Advanced Design Patterns 13. Testing Object-Oriented Programs 14. Concurrency 15. Other Books You May Enjoy
16. Index

Generator functions

Generator functions embody the essential features of a generator expression, which is the generalization of a comprehension. The generator function syntax looks even less object-oriented than anything we've seen, but we'll discover that once again, it is a syntax shortcut to create a kind of iterator object. It helps us build processing following the standard iterator-filter-mapping pattern.

Let's take the log file example a little further. If we want to decompose the log into columns, we'll have to do a more significant transformation as part of the mapping step. This will involve a regular expression to find the timestamp, the severity word, and the message as a whole. We'll look at a number of solutions to this problem to show how generators and generator functions can be applied to create the objects we want.

Here's a version, avoiding generator expressions entirely:

import csv
import re
from pathlib import Path
from...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}