Python使用urllib下载文件以及使用zipfile解压文件

首先定义文件下载路径,文件名

import os
from six.moves import urllib
import zipfile
DATA_URL = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00240/UCI%20HAR%20Dataset.zip'
DATA_DIR = './dataset/'
DATA_NAME = 'UCI HAR Dataset.zip'

filename = DATA_NAME
filepath = os.path.join(DATA_DIR, filename)

下载文件:

filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath)

解压文件:

with zipfile.ZipFile(filepath, 'r') as zip:
    zip.extractall(DATA_DIR)

 

    原文作者:Kenn7
    原文地址: https://blog.csdn.net/kane7csdn/article/details/84025393
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞