Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nate Brunelle Today: Web Reading

Similar presentations


Presentation on theme: "Nate Brunelle Today: Web Reading"— Presentation transcript:

1 Nate Brunelle Today: Web Reading
CS1110 Nate Brunelle Today: Web Reading

2 Questions?

3 Representing Data as Text
CSV format: Comma Separated Values Data has records: One record per line Records separated by \n (newline) E.g. one purchase (Pears,2.8) Records have cells: Separated by , Each record must have the same number of cells E.g. the thing purchased (Pears) Apples,10.0 Pears,2.8 Peaches,5.2 Grapes,19.4 Apples,100.0

4 Processing a CSV Split text into lines (i.e. records)
Split each line (record) into cells Do what we wanted to do with the cells

5 read() vs. readline() readline(): read(): readlines():
Gives the next line of text from the file read(): Gives the rest of the file as a string readlines(): Gives the rest of the file as a list of strings

6 Reading a file vs. web import urllib.request
s = open(filename, ‘r’) for x in s: c = x.strip().split(‘,’) … import urllib.request s = urllib.request.urlopen(url) for x in s: x = x.decode(‘utf-8’) c = x.strip().split(‘,’)


Download ppt "Nate Brunelle Today: Web Reading"

Similar presentations


Ads by Google