I’m trying to create a zipfile from a JSON file in Python (3.9). When I do this with my dev computer (Windows) it’s works perfectly, but when I push my script on my production server (Linux Alma 8), the zipfile contains all the parents folders…
For example, if my script is located at /opt/my_script/script.py and my files at /opt/my_script/my_folder/file_1.json it will create a zip file with an opt folder, a my_script folder inside, a my_folder folder inside and then my json file.
Can you please explain me the way to fix it ?
My script :
dir = '/'.join([path.dirname(path.abspath(__file__)),'my_folder'])
os.chdir(dir)
zip = zipfile.ZipFile('.'.join([file_name,'zip']),'w',zipfile.ZIP_DEFLATED)
zip.write('.'.join([file_name,'json']))
zip.close()
Thank you for your help.
MELEY is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.