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 second example

Let's see (in the rx_example2.py file) another way to write the code and obtain a similar result as in the first example.

We adopt the get_quotes() function in order to return an enumeration of the sequence, using Python's built-in enumerate() function, as follows:

def get_quotes():    import contextlib, io    zen = io.StringIO()    with contextlib.redirect_stdout(zen):        import this    quotes = zen.getvalue().split('\n')[1:]    return enumerate(quotes)

We can call that function and store its result in a variable, zen_quotes:

zen_quotes = get_quotes()

We create the Observable using the special Observable.from_() function and chain operations such as filter() on the sequence, and finally use subscribe() to subscribe to the Observable.

See ...
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