''' Purpose: practice getting data from a useful dataset ''' # define the base folder for course csv datasets CSV_WEB_FOLDER = "http://www.cs.virginia.edu/~cs1112/datasets/csv/" ############### BOILER PLATE TO GET CONTENTS OF WEB FILE ############### # need help to get web data - so import the capability from urllib.request import urlopen # get name of the dataset reply = input( "Enter name of dataset: " ) print() # clean up the reply to get file name file_name = reply.strip() # get url link for dataset link = CSV_WEB_FOLDER + file_name # get a connection to stream the web resource of interest stream = urlopen( link ) # read stream to gets its encoded contents encoding = stream.read() # decode contents into plain text form text = encoding.decode( 'UTF-8' ) # clean-up the text text = text.strip() print( text ) ############### TURN CONTENTS INTO A LIST OF LINES ############### # turn the text into data; i.e., a list of lines lines = text.split( "\n" ) ############### TURN LINES INTO A DATASET -- LIST OF LISTS ############### # get csv rows into dataset from dataset = [] for line in lines : # clean up the line line = ... # split the line to cells cells = ... row = [] for cell in cells : # clean up the cell ... # add the cell to the row ... # add the row of data to our dataset ... # print the dataset for row in dataset : print( row )