zip a created file

Tino Wildenhain tino at wildenhain.de
Sat Dec 13 19:43:57 CET 2008


frendy zhang wrote:
> if form.accepts(request.vars,session):
>         for table in db.tables:
>             rows=db(db[table].id).select()
>             print rows
>             open(str(os.sep).join([os.getcwd(), 'applications',
>                 request.application, 'databases',
>                 table+'.csv']),'w').write(str(db(db[table].id).select ()))
> 
>  
> where and what should i put the zip code to zip the file created above?
> thanks in advance

You don't? ;) The code is very -crappy- suboptimal... - can you
reformulate the problem first?

Where is request, session coming from? If its a web application,
what are you doing with open() and why this complicated code
instead of just os.path.join() ?

In short, creating a file and zipping and sending to the browser
should not need to create an intermediate file in the file
system. (This also avoids a lot of problems with your approach
above - for example if the same query is put twice the same time...)

Just have a look at the examples in the documentation which come
with the zipfile module.


Cheers
Tino

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20081213/24eb3509/attachment.bin>


More information about the Python-list mailing list