just like i said,it's a very strange question.i hope you guys could help me solve this question thanks
the following is my code:
import os
import zipfile
filename = "E:\\test.zip"
currdir = "E:\\vpn\\"
os.chdir(currdir)
tfile = zipfile.ZipFile(filename, 'w')
files = os.listdir(currdir)
for f in files:
tfile.write(f)
for f in tfile.namelist():
print "added %s"%f
tfile.close()
the error message:
Traceback (most recent call last):
File "C:\pydemo\src\gzip\zipfile.py", line 7, in <module>
import zipfile
File "C:\pydemo\src\gzip\zipfile.py", line 14, in <module>
tfile = zipfile.ZipFile.(filename, 'w')
AttributeError: 'module' object has no attribute 'ZipFile'
You called your script zipfile.py
, which means it is trying to import itself. Change the name of the file to basically anything else.
Your module is importing itself as zipfile. Call it something other than zipfile.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With