[AI数据]在线获取和解压压缩包

import os
import tarfile
import urllib
import pandas as pd

DOWNLOAD_ROOT = "https://example/"
HOUSING_PATH = os.path.join("datasets", "housing")
HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz"

# fetch housing data
def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):
    os.makedirs(housing_path, exist_ok=True)
    tgz_path = os.path.join(housing_path, "housing.tgz")
    urllib.request.urlretrieve(housing_url, tgz_path)
    housing_tgz = tarfile.open(tgz_path)
    housing_tgz.extractall(path=housing_path)
    housing_tgz.close()

知识点:

os.makedirs

urllib.request.urlretrieve

tarfile.open/extractall


版权声明:本文为guaguastd原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。