import urllib.request import os import tarfile #下载数据集 url="http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz" filepath="data/aclImdb_v1.tar.gz" if not os.path.isfile(filepath): result=urllib.request.urlretrieve(url,filepath) print('downloaded:',result) # 解压 if not os.path.exists("data/aclImdb"): tfile = tarfile.open("data/aclImdb_v1.tar.gz", 'r:gz') result=tfile.extractall('data/')