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'
2 个解决方案
#1
10
You called your script zipfile.py
, which means it is trying to import itself. Change the name of the file to basically anything else.
您调用了脚本zipfile.py,这意味着它正在尝试导入自己。将文件名更改为其他任何内容。
#2
3
Your module is importing itself as zipfile. Call it something other than zipfile.py
您的模块将自己导入为zipfile。称之为zipfile.py以外的东西
#1
10
You called your script zipfile.py
, which means it is trying to import itself. Change the name of the file to basically anything else.
您调用了脚本zipfile.py,这意味着它正在尝试导入自己。将文件名更改为其他任何内容。
#2
3
Your module is importing itself as zipfile. Call it something other than zipfile.py
您的模块将自己导入为zipfile。称之为zipfile.py以外的东西