sending signals to the calling function

Tim Golden tim.golden at viacom-outdoor.co.uk
Mon Jun 28 11:24:31 CEST 2004


| 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

<code>

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________




More information about the Python-list mailing list