blob: a7b46cb63f4e57a079cc684019b4176a4ea97376 [file] [log] [blame]
Guido van Rossum368f04a2000-04-10 13:23:04 +00001import zipfile, os
2
3srcname = "junk9630.tmp"
4zipname = "junk9708.tmp"
5
6try:
Fred Drake004d5e62000-10-23 17:22:08 +00007 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()
Guido van Rossum368f04a2000-04-10 13:23:04 +000011
Fred Drake004d5e62000-10-23 17:22:08 +000012 zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
13 zip.write(srcname, srcname)
14 zip.write(srcname, "another.name")
15 zip.close()
Guido van Rossum368f04a2000-04-10 13:23:04 +000016
Fred Drake004d5e62000-10-23 17:22:08 +000017 zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive
18 zip.read("another.name")
19 zip.read(srcname)
20 zip.close()
Guido van Rossum368f04a2000-04-10 13:23:04 +000021finally:
Fred Drake004d5e62000-10-23 17:22:08 +000022 if os.path.isfile(srcname): # Remove temporary files
23 os.unlink(srcname)
24 if os.path.isfile(zipname):
25 os.unlink(zipname)