Adding a .txt to an already zipped file
Question: I have created this small python program to automate some processes I want to
run. Long story short I use python to pass some information and parameters to
a outside program. The outside program does its thing and zips up the results.
What I am trying to do is add a "licence.txt" file to the already zipped
results. This is what I have:

    
    
    import zipfile
    
    #List of files for the licence to be inserted into
    data = [ loc + r"\FME_Data\FME_GENERIC_OUTPUT\BASE\BASE_NS_CivicAddress_File_UT83_GDB.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\BASE\BASE_NS_CivicAddress_File_UT83_MIF.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\BASE\BASE_NS_CivicAddress_File_UT83_SHP.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\BND\BND_NS_Community_Bndys_UT83_GDB.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\BND\BND_NS_Community_Bndys_UT83_MIF.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\BND\BND_NS_Community_Bndys_UT83_SHP.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\TRNS\TRNS_NSRN_Addressed_Roads_UT83_GDB.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\TRNS\TRNS_NSRN_Addressed_Roads_UT83_MIF.zip",
             loc + r"\FME_Data\FME_GENERIC_OUTPUT\TRNS\TRNS_NSRN_Addressed_Roads_UT83_SHP.zip"]
    
    
    count, tot = 0,8
    while count <= tot:
         z = zipfile.ZipFile(data[count] , "a")
         z.write ("Licence.txt")
         z.close()
         count = count + 1
    

This runs and it inserts the .txt into the zip files, but it is also copying
all the other individual .zip files into each zipped directory. So I end up
with the 9 separate zipped files zipped into each directory. There should only
be one file type in each .zip. I feel as though I made a real simple mistake
but I can't find it... Any ideas?


Answer: I don't see why yours would do that but try this, it is a bit simpler:

    
    
    import zipfile
    for filepath in data:
       with zipfile.ZipFile(filepath, 'a') as myzip:
          myzip.write('license.txt')
    

