Reading streaming data sources

What if the data that is coming from the source is continuous? What if we need to read continuous data? This recipe will demonstrate a simple solution that will work for many common real-life scenarios, but it is not universal and you will need to modify it if you hit a special case in your application.

How to do it...

In this recipe, we will show you how to read an ever-changing file and print the output. We will use the common Python module to accomplish this as shown here:

import time import os import sys if len(sys.argv) != 2: print >> sys.stderr, "Please specify filename to read" filename = sys.argv[1] if not os.path.isfile(filename): print >> sys.stderr, "Given file: \"%s\" is not a file" % filename with open(filename,'r') ...

Get Python Data Visualization Cookbook - Second Edition 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.