Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python read gzipped file

# Basic syntax:
import gzip
with gzip.open("your_file.gz", mode="rt") as file:
    file_as_list = file.read().splitlines()
# Where:
#	- gzip.open allows you to open gzipped files like you would open regular
#		files with open
#	- the default mode is rb (read binary), which loads the file contents as
#		binary strings. Use mode="rt" to read the file as text
#	- .read() reads the entire file
#	- .splitlines() splits the file by newline characters to create a list
# Note, see answer to "python open" for more ways to open and parse files
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #read #gzipped #file
ADD COMMENT
Topic
Name
8+7 =