how to zip a StringIO object?
Nagy Viktor
viktor.nagy.aw at gmail.com
Wed Oct 28 11:48:44 EDT 2009
Hi,
I try to run the following code:
def generate_zip(object_list, template):
result = StringIO.StringIO()
zipped = zipfile.ZipFile(result, "w")
for object in object_list:
pdf = generate_pdf(object, template)
if not pdf:
raise IOError("Problem with generating invoice %d" %
object.pk)
zipped.writestr("invoice-%d.pdf" % object.pk, pdf)
zipped.close()
return result.getvalue()
where generate_pdf returns a valid pdf file's string content, more
precisely it returns a StringIO.getvalue() call containing the pdf
"string".
When I add this string to the zip file, I get a problem. Namely, the
zipped files are chmoded to non-readable when extracted. How can I
change this?
thanks,
V
More information about the Python-list
mailing list