Saving Web dataset into a file, Pickling that file, then Unpickling it

    

   import pickle
import requests
# getting iris dataset from a web address
resp = requests.get("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data")
# saving the web data into a text file
with open("iris.txt", "w") as f:
    f.write(resp.text)
# reading the created text file containing the web data   
with open("iris.txt", "r") as f:
    dataset = f.read()
# splitting the web data in text file
listof = dataset.split("\n")
# converting list into list of lists
lol = [[item] for item in listof]
# pickling the data
pickleed = open("irislists.pkl", "wb")
pickle.dump(file=pickleed, obj=lol)
pickleed.close()
# unpickling the data
unpickleed = open("irislists.pkl", "rb")
pythonobj = pickle.load(file=unpickleed)
print(pythonobj)
unpickleed.close()

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes