0
我使用美麗的湯從URL中取出文件,然後想要使用Python將這些文件存儲在單個壓縮文件中。以下是我的一個URL的代碼片段。如何使用python在一個zip文件中保存多個文件?
fz = zipfile.ZipFile('C:\\Users\\ADMIN\\data\\data.zip', 'w')
response = urllib2.urlopen(url/file_name.txt)
file = open('C:\\Users\\ADMIN\\data\\filename.txt','w')
file.write(response.read())
file.close()
fz.write('C:\\Users\\ADMIN\\data\\filename.txt',compress_type=zipfile.ZIP_DEFLATED) fz.close()
這段代碼不適合我,任何人都可以幫我解決這個問題。得到低於錯誤:
WindowsError: [Error 2] The system cannot find the file specified: 'C:\Users\ADMIN\data\filename.txt'
但文件存在於此位置。
似乎在這裏工作。 – Goyo