Create ZIP File with Specified File

  • Share this:

Code introduction


This function uses the zipfile module to create a ZIP file and adds the specified file to the ZIP file.


Technology Stack : zipfile, os

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfile(arg1, arg2):
    import zipfile
    import os

    with zipfile.ZipFile(arg1, 'w') as zipf:
        zipf.write(arg2, os.path.basename(arg2))

    return zipfile.ZipFile(arg1, 'r')                
              
Tags: