Skip to Content
Mastering Python Design Patterns - Second Edition
book

Mastering Python Design Patterns - Second Edition

by Kamon Ayeva, Sakis Kasampalis
August 2018
Intermediate to advanced
248 pages
5h 51m
English
Packt Publishing
Content preview from Mastering Python Design Patterns - Second Edition

A fourth example

Let's build a stream of the list of people and an Observable based on it.

Here is another trick: To help you handle the data source, we will use a third-party module called Faker (https://pypi.org/project/Faker) to generate the names of people.

You can install the Faker module using the pip install faker command.

In the peoplelist.py file, we have the following code, with a populate() function that leverages a Faker instance to generate the first name and last name of fictitious people:

from faker import Fakerfake = Faker()def populate():    persons = []    for _ in range(0, 20):        p = {'firstname': fake.first_name(), 'lastname': fake.last_name()}        persons.append(p)    return iter(persons)

For the main part of the program, we write the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python Design Patterns - Second Edition - Second Edition

Learning Python Design Patterns - Second Edition - Second Edition

Chetan Giridhar, Gennadiy Zlobin

Publisher Resources

ISBN: 9781788837484Supplemental Content