PYTHON   32
accessRemoteFile
Guest on 27th August 2023 06:06:36 AM


  1. import urllib.request
  2.  
  3. #Find out how much the Earth slowed down between 1821 and 1970.
  4.  
  5. #You won't be responsible for the "urllib.request"
  6. #  module on the exam; it's interesting to see this
  7. #  kind of functionality.
  8.  
  9. def main():
  10.     url = 'http://cs.toronto.edu/~pgries/pybook/data/TSDL/andrews5.dat.txt'
  11.     localFile, headers = urllib.request.urlretrieve(url)
  12.     contents = open(localFile)
  13.     total = 0
  14.     for line in contents:
  15.         print(line,end="")
  16.         values = line.split()
  17.         for num in values:
  18.             total = total + int(num)
  19.     contents.close()
  20.     print("total is",total)
  21.  
  22. main()

Raw Paste

Login or Register to edit or fork this paste. It's free.