import os
import tarfile
from six.moves import urllib
DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"
HOUSING_PATH = os.path.join("datasets", "housing")
HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz"
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()
远程获取数据解压保存到指定目录 | urllib、tarfile、os
最新推荐文章于 2021-05-11 10:34:07 发布