我有这段代码:
# File: zipfile-example-1.py
import zipfile,os,glob
file = zipfile.ZipFile("Apap.zip", "w")
# list filenames
for name in glob.glob("C:\Users/*"):
print name
file.write(name,os.path.basename(name),zipfile.ZIP_DEFLATED)
file = zipfile.ZipFile("Apap.zip", "r")
for info in file.infolist():
print info.filename, info.date_time, info.file_size, info.compress_size
这会导致产生以下错误:
raceback (most recent call last):
File "C:/Users/Desktop/zip.py", line 11, in <module>
file = zipfile.ZipFile("Apap.zip", "r")
File "C:\Python27\lib\zipfile.py", line 712, in __init__
self._GetContents()
File "C:\Python27\lib\zipfile.py", line 746, in _GetContents
self._RealGetContents()
File "C:\Python27\lib\zipfile.py", line 761, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file
有人知道为什么会出现这个错误吗?