There's more...

This write could have simply been handled using a function that wraps the code.  This object will be reused throughout this chapter. We could use the duck-typing of python, or just a function, but the clarity of interfaces is easier.  Speaking of that, the following is the definition of this interface:

""" Defines the interface for writing a blob of data to storage """from interface import Interfaceclass IBlobWriter(Interface):   def write(self, filename, contents):      pass

We will also see another implementation of this interface that lets us store files in S3.  Through this type of implementation, through interface inheritance, we can easily substitute implementations.

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.