Reputation: 115
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'
Upvotes: 6
Views: 12431
Reputation: 3229
Your module is importing itself as zipfile. Call it something other than zipfile.py
Upvotes: 5
Reputation: 78590
You called your script zipfile.py
, which means it is trying to import itself. Change the name of the file to basically anything else.
Upvotes: 15