''' Purpose: introduce web data acquisition -- print contents of word-of-the-day.txt from http://www.cs.virginia.edu/~cs1112/datasets/words/ ''' # need help to get web data - so import the capability from urllib.request import urlopen # IMPORTANT CONSTANTS CS1112_WORDS_WEB_FOLDER = "http://www.cs.virginia.edu/~cs1112/datasets/words/" FILE_NAME = "word-of-the-day" # get a link to file of interest link = CS1112_WORDS_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 text to get the word word = text.strip() # print word of the day print( word )