home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_ZIPFILE.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  663 b   |  27 lines

  1. import zipfile, os
  2.  
  3. srcname = "junk9630.tmp"
  4. zipname = "junk9708.tmp"
  5.  
  6. try:
  7.   fp = open(srcname, "w")        # Make a source file with some lines
  8.   for i in range(0, 1000):
  9.     fp.write("Test of zipfile line %d.\n" % i)
  10.   fp.close()
  11.  
  12.   zip = zipfile.ZipFile(zipname, "w")    # Create the ZIP archive
  13.   zip.write(srcname, srcname)
  14.   zip.write(srcname, "another.name")
  15.   zip.close()
  16.  
  17.   zip = zipfile.ZipFile(zipname, "r")    # Read the ZIP archive
  18.   zip.read("another.name")
  19.   zip.read(srcname)
  20.   zip.close()
  21. finally:
  22.   if os.path.isfile(srcname):        # Remove temporary files
  23.     os.unlink(srcname)
  24.   if os.path.isfile(zipname):
  25.     os.unlink(zipname)
  26.  
  27.