zoukankan      html  css  js  c++  java
  • using python zipFile: strange 'BadZipfile'

    using GAE with Python

    wanna generate a zip file from the server with some server-generated rtf files.

     1 import zipfile
     2 from cStringIO import StringIO 
     3 
     4 zipStream = StringIO()
     5 = zipfile.ZipFile(zipStream, 'w', zipfile.ZIP_DEFLATED)
     6 
     7 #f = StringIO()
     8 #generated by another lib
     9 #f could be any string
    10 z.writestr('test.rtf', f.getvalue())
    11 z.close()
    12 zipStream.seek(0)
    13 self.response.out.write(zipStream.getvalue())

     someone said we could not use the return value if the ZipFile was created by passing in a file-like object

    http://stackoverflow.com/questions/583791/is-it-possible-to-generate-and-return-a-zip-file-with-app-engine

     i found that we could add 

    z.close()
    zipStream.seek(0)

     then the 'BadZipfile' is gone.

     that's strange.

  • 相关阅读:
    线性最大子数组的求法(二)
    高难度智力题
    职业规划
    良好的学习习惯
    毕业生面试绝招
    编写Java程序最容易犯的21种错误
    spring02
    spring_01
    用soapUI生成客户端代码
    idea创建git分支
  • 原文地址:https://www.cnblogs.com/liyinkan/p/2098789.html
Copyright © 2011-2022 走看看