Python – May 20 Reading data from the Web Example: web.py Practice with large amount of I/O See lab sheet
Web input Just like Java, Python has an easy way to automatically read a Web page import urllib2 page = urllib2.urlopen(“http://--------”) Can continue as if “page” is an input file for line in page: Example: web.py reads a stock quote.
Large input Algorithm needs to be practical, in addition to correct. Beware of nested loops Comments about the data; “density” #3 - County population, area, density Assume that all blocks in county are listed together. #5 – Creating tract-level data Need to look up tract in dictionary search for tract, because blocks in input file are not sorted by tract Once you are finished with a county, you can output all its tracts and empty the dictionary.