Implementation
Instead of building a complete implementation here, we will approach different possibilities and see how you can use them.
To get started, install RxPY in your Python environment using the pip install rx
command.
A first example
To start, let's take the example from the RxPY documentation and write a more fun variant. We are going to observe a stream built from the Zen of Python quotes by Tim Peters (https://www.python.org/dev/peps/pep-0020/).
Normally, you can see the quotes by using import this
in the Python console, as you can see in the following screenshot of the console:
>>> import this

Then, the question is how to get that list of quotes from within a Python program. A quick search gives us an answer on Stack Overflow. Basically, you can redirect the result of the import this
statement to an io.StringIO
instance and then access it and print it using print()
, as follows:
import contextlib, io zen = io.StringIO() with contextlib.redirect_stdout(zen): import this...