python ZipFile mode append misbehaving

7 views
Skip to first unread message

Ritesh Raj Sarraf

unread,
Jun 29, 2006, 3:33:33 AM6/29/06
to Linux-Nepal
Hi,

I've got a problem here.


def compress_the_file(zip_file_name, files_to_compress, sSourceDir):
"""
Condenses all the files into one single file for easy transfer
"""


try:
import zipfile
except ImportError:
sys.stderr.write("Aieeee! module not found.\n")


try:
os.chdir(sSourceDir)
except:
#TODO: Handle this exception
pass


filename = zipfile.ZipFile(zip_file_name, "a")
# try:
# filename = zipfile.ZipFile(zip_file_name, "a")
# except:
# #TODO Handle the exception
# sys.stderr.write("\nAieee! Some error exception in creating
zip file %s\n" % (zip_file_name))
# sys.exit(1)


filename.write(files_to_compress, files_to_compress,
zipfile.ZIP_DEFLATED)
filename.close()


The line
filename = zipfile.ZipFile(zip_file_name, "a")
throws an exception if the given filename is not present already.
Shouldn't it create a file (in case one is not there) since it is
"append" mode ??


Ritesh

Reply all
Reply to author
Forward
0 new messages