I want to write a json file to a zip folder that's in a function The issue is: at the end of the function I must close the zip so when I re-run the function and save another json to it it won't save as its closed. I'm super beginner can anyone give some direction/guidance?
def ExportJson(files):
now = datetime.now()
now_date = now.strftime("%d%m%y")
# new json name
new_json_name = now_date + new_fname + ".json"
# saves dataframe to json
files.to_json(new_json_name)
# new zip file name
new_zip_name = work_dir + "/" + new_fname + ".zip"
# Create new zip file
zip_file = zipfile.ZipFile(new_zip_name, 'w', zipfile.ZIP_DEFLATED)
# Write json to zip
zip_file.write(new_json_name)
zip_file.close()