'How to make the rest of the code wait until zipfile finishes compiling files

I'm writing a script that compresses multiple files and then uploads the zip file into Google Drive. I managed to do both of these actions separately but when I do them together the uploading begins before the files have been zipped.

# final part of the creating zip file process:
with zipfile.ZipFile(zipFileName+".zip", "w") as zf:
    for f in myFiles:
        zf.write(f)
        print(f)

# last part of the uploading process
file_name = (zipFileName+'.zip')
metadata = {'name': file_name,
            'mimeType': None
            }

res = DRIVE.files().create(body=metadata, media_body=file_name).execute()
if res:
    print('Uploaded "%s" (%s)' % (file_name, res['mimeType']))

My hypothetical solution is to make the zipfile process wait but I'm not sure how to go about that.



Solution 1:[1]

This is essentially what worked for me:

zipFileName = input("What do you want to call the zip file?: ")
try:
    zipTheFiles(zipFileName)
except:
    print("Failed to zip the files")
else:
    shipIt(zipFileName)

I split the code into two functrions and placed them in a try,except,else statement

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MoreeZ