我正在使用zipfile模块.
这是我到目前为止所提出的:
# fetch the zip file from its remote URLresult = urlfetch.fetch(zip_url)# store the contents in a streamfile_stream = StringIO.StringIO(result.content)# create the Zipfile objectzip_file = zipfile.Zipfile(file_stream,'w')# read the files by namearchive_files = zip_file.nameList()
不幸的是,archive_files列表的长度始终为0.
我有什么想法我做错了吗?
解决方法 您正在使用w权限打开文件,这会截断它.将其更改为r读取权限:zip_file = zipfile.Zipfile(file_stream,'r')
参考:http://docs.python.org/library/zipfile.html#zipfile-objects
总结以上是内存溢出为你收集整理的python – 获取远程zip文件并列出其中的文件全部内容,希望文章能够帮你解决python – 获取远程zip文件并列出其中的文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)