How to access a folder in a zip file?

mignoncharly mignoncharly at yahoo.fr
Sat Jan 19 08:36:01 EST 2019


Hello!

I'm a newbie in python and I was trying to access a folder inside a zip file and I also have issues with relative and absolute path. Thks in advance.

In projects there a lot of urls (i'll read them later one by one and store them in a list/array so that I could work with it easily)

here is the path:  home/name/tutorial/prof/ks.zip/projects

should I use 

file_name = "ks.zip" 

or

file_location = os.path.dirname(os.path.abspath(__file__))
#print(file_location)  ?



# specifying the zip file name
file_name = "ks.zip"

 # opening the zip file in READ mode
with ZipFile(file_name, 'r') as zip:

   # printing all the contents of the zip file
   zip.printdir()

    # extracting all the files
   print('Extracting all the files now...')
   zip.extractall()
   print('Done!')



More information about the Python-list mailing list