sending signals to the calling function
Haim Ashkenazi
haim at babysnakes.org
Mon Jun 28 05:40:48 EDT 2004
On Mon, 2004-06-28 at 12:24, Tim Golden wrote:
> | I have a function that receive a list of files and creates a zip from
> | these files. I want it to send signal to the calling function with the
> | name of the file it currently compressing. is there a way to do this
> | (without threads)?
>
> Of course, just pass in a callback function, and call that
> whenever a file is being compressed. Alternatively, make
> the zipper-upper a generator which yields its current filename:
>
> <code>
>
> import os, sys
> import zipfile
>
> def zipup (zip_filename, list_of_files):
> archive = zipfile.ZipFile (zip_filename, "w")
> for filename in list_of_files:
> yield filename
> archive.write (filename)
> archive.close ()
>
> if __name__ == '__main__':
> import glob
> file_pattern = os.path.join (sys.path[-1], "*")
> list_of_files = [f for f in glob.glob (file_pattern) if os.path.isfile
> (f)]
> for zipping_file in zipup ("test.zip", list_of_files):
> print "About to zip", zipping_file
thanx, that's exactly what I needed.
Bye
--
Haim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20040628/4b5c71c9/attachment.sig>
More information about the Python-list
mailing list