Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python read zipfile

# Extract all contents from zip file
import zipfile
with zipfile.ZipFile('filename', 'r') as myzip: #'r' reads file, 'w' writes file
    myzip.extractall()
# The zipfile will be extracted and content will be available in your working
# directory.
Comment

extract zip file in python zipfile

from zipfile import ZipFile
import zipfile

with ZipFile('test.zip') as myzip:
    with myzip.open('Roughwork/textfile.text') as myfile:
        print(myfile.readlines())Copy Code
Comment

python zip files

import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
Comment

python zip file

import shutil
import zipfile

# base_name is the name of the zip file you want to create
# format is zip for zip file
# root_dir is the direct path of the folder or file you want to zip
shutil.make_archive(base_name='zip_file_name', format='zip', root_dir='data')

# read zip file from current path
with zipfile.ZipFile(file='zip_file_name.zip', mode='r') as zip_ref:
   # create folder name extract_data in current directory with the extracted data
   zip_ref.extractall(path='extract_data')

# Extract a single file from a zip file
with zipfile.ZipFile(file='zip_file_name.zip', mode='r') as zip_ref:
   # Extract a file name called secrets.dat
   zip_ref.extract(member='secrets.dat')
  
 # extract a list of filename within a zip file
with zipfile.ZipFile(file='zip_file_name.zip', mode='r') as zip_obj:
    # Get list of files names in zip
    filenames = zip_obj.namelist()

    # Iterate over the list of file names in given list & print them
    for filename in filenames:
        print(filename)
Comment

python open zip file

with ZipFile('spam.zip') as myzip:
    with myzip.open('eggs.txt') as myfile:
        print(myfile.read())
Comment

PREVIOUS NEXT
Code Example
Python :: base64 python decode 
Python :: How to set font size of Entry in Tkinter 
Python :: pandas print all columns 
Python :: latency discord.py 
Python :: root number in python 
Python :: python delete file with extension 
Python :: youtube upload python 
Python :: drf default pagination 
Python :: python code to remove vowels from a string 
Python :: python datetime from string 
Python :: execute command in python script 
Python :: python catch sigterm 
Python :: tkinter starter code 
Python :: star operator python 
Python :: add colorbar to figure matplotlib line plots 
Python :: colab pip 
Python :: How to Create Caesar Cipher Using Python 
Python :: how to make it so we can give unlimited parameters in python function 
Python :: get count of unique values in column pandas 
Python :: python smtp email 
Python :: 2d array pytho 
Python :: current time python 
Python :: await async function from non async python 
Python :: remove empty lines from file python 
Python :: django connection cursor 
Python :: find how many of each columns value pd 
Python :: pynput.keyboard.Key 
Python :: remove particular row number in pandas 
Python :: python average 
Python :: using tqdm in for loop 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =