Wednesday, December 18, 2019

Working with Zip file in python(writing)

                     Working with Zip File in Python(Writing)
Module in Python to write zip file:   
                 The zipfile module can be used to manipulate ZIP archive files.Sometimes it is necessary to write 
                to a ZIP archive using data that did not come from an existing file. Rather than writing the data to 
                a file, then adding that file to the  ZIP archive, you can use the writestr() method to add a string 
                of bytes to the archive directly.

                           from zipfile_infolist import print_info
                           import zipfile

                           msg = 'This data did not exist in a file before being added to the ZIP file'
                           zf = zipfile.ZipFile('', mode='w', compression=zipfile.ZIP_DEFLATED,) 
                               zf.writestr('from_string.txt', msg)
                          zf = zipfile.Zip File('', 'r')
                    $ python
                    Comment:        Remarks go here
                    Modified:       2019-11-14 11:44:14
                    System:         0 (10 = Windows)
                    ZIP version:    20
                    Compressed:     62 bytes
                    Uncompressed:   64 bytes           
A directory with such a format:
                          # importing required modules
from zipfile import ZipFile
import os
def get_all_file_paths(directory):
     # initializing empty file paths list
     file_paths = []
     # crawling through directory and subdirectories
     for root, directories, files in os.walk(directory):
         for filename in files:
             # join the two strings in order to form the full filepath.
             filepath = os.path.join(root, filename)
     # returning all file paths
     return file_paths        
def main():
     # path to folder which needs to be zipped
     directory = './python_files'
     # calling function to get all file paths in the directory
     file_paths = get_all_file_paths(directory)
     # printing the list of all files to be zipped
     print('Following files will be zipped:')
     for file_name in file_paths:
     # writing files to a zipfile
     with ZipFile('','w') as zip:
         # writing each file one by one
         for file in file_paths:
     print('All files zipped successfully!')        
if __name__ == "__main__":

Following files will be zipped:
All files zipped successfully!
                          def get_all_file_paths(directory):
                                   file_paths = []

                                   for root, directories, files in os.walk(directory):
                                           for filename in files:
                                               filepath = os.path.join(root, filename)

                                  return file_paths                              

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...