我正在学习Python和相关模块。这是我的脚本。
import tarfile
from six.moves import urllib
data_path = "./datasets/housing/"
file = "housing.tgz"
data_path_file = data_path + file
tar_file = tarfile.open(data_path_file)
# tested following script, failed
tar_file = tarfile.open(data_path_file,'r')
# end test
tar_file.extractall(path=data_path_file)
我希望我的脚本可以解压缩tgz文件并将其写入新文件。我总是收到以下错误消息:
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully
我检查了路径和文件名。没有错误。任何纠正和进一步的帮助将不胜感激。