gzip

Python unzip multiple .gz files

Python unzip multiple .gz files Question: I have compressed a file into several chunks using 7zip: HAVE: foo.txt.gz.001 foo.txt.gz.002 foo.txt.gz.003 foo.txt.gz.004 foo.txt.gz.005 WANT: foo.txt How do I unzip and combine these chunks to get a single file using python? Asked By: r0f1 || Source Answers: First you must extract all the zip files sequentially: import …

Total answers: 3

Counting the number of lines in a gzip file using python

Counting the number of lines in a gzip file using python Question: I’m trying to count the number of lines in a gz archive. There is only 1 json format text file per gz. But when I open the archive and count the lines the count is way off what I’d expect. The file contains …

Total answers: 2

GzipFile instance has no attribute '__exit__' when used in a "with:" block

GzipFile instance has no attribute '__exit__' when used in a "with:" block Question: I need to process a .gz file with Python. I pass the filename into my Python script with: infile = sys.argv[1] with gzip.open(infile, ‘rb’) as f: logfile = f.read() which gives me: with gzip.open(infile, ‘rb’) as f: AttributeError: GzipFile instance has no …

Total answers: 2

Python: Read compressed (.gz) HDF file without writing and saving uncompressed file

Python: Read compressed (.gz) HDF file without writing and saving uncompressed file Question: I have a large number of compressed HDF files, which I need to read. file1.HDF.gz file2.HDF.gz file3.HDF.gz … I can read in uncompressed HDF files with the following method from pyhdf.SD import SD, SDC import os os.system(‘gunzip < file1.HDF.gz > file1.HDF’) HDF …

Total answers: 2

can I read and write files in tar.gz without decompression?

can I read and write files in tar.gz without decompression? Question: PROBLEM OUTLINE: can we read and write files in tar.gz without decompression? I have many tar.gz files named like GF1_PMS1_E72.0_N33.6_20160507_L1A0001568810.tar.gz each of the tar.gz file contains the files like below: GF1_PMS1_E72.6_N33.6_20160511_L1A0001576267-MSS1.tiff GF1_PMS1_E72.6_N33.6_20160511_L1A0001576267-MSS1.xml GF1_PMS1_E72.6_N33.6_20160511_L1A0001576267-MSS1.rpb GF1_PMS1_E72.6_N33.6_20160511_L1A0001576267-MSS1.jpg I want to read the tiff to numpy array without …

Total answers: 2

Python checking integrity of gzip archive

Python checking integrity of gzip archive Question: Is there a way in Python using gzip or other module to check the integrity of the gzip archive? Basically is there equivalent in Python to what the following does: gunzip -t my_archive.gz Asked By: wwn || Source Answers: you can use subprocess or os module to execute …

Total answers: 2

How can I read tar.gz file using pandas read_csv with gzip compression option?

How can I read tar.gz file using pandas read_csv with gzip compression option? Question: I have a very simple csv, with the following data, compressed inside the tar.gz file. I need to read that in dataframe using pandas.read_csv. A B 0 1 4 1 2 5 2 3 6 import pandas as pd pd.read_csv(“sample.tar.gz”,compression=’gzip’) However, …

Total answers: 2

Read .tar.gz file in Python

Read .tar.gz file in Python Question: I have a text file of 25GB. so i compressed it to tar.gz and it became 450 MB. now i want to read that file from python and process the text data.for this i referred question . but in my case code doesn’t work. the code is as follows …

Total answers: 6

Apply GZIP compression to a CSV in Python Pandas

Apply GZIP compression to a CSV in Python Pandas Question: I am trying to write a dataframe to a gzipped csv in python pandas, using the following: import pandas as pd import datetime import csv import gzip # Get data (with previous connection and script variables) df = pd.read_sql_query(script, conn) # Create today’s date, to …

Total answers: 4

Writing then reading in-memory bytes (BytesIO) gives a blank result

Writing then reading in-memory bytes (BytesIO) gives a blank result Question: I wanted to try out the python BytesIO class. As an experiment I tried writing to a zip file in memory, and then reading the bytes back out of that zip file. So instead of passing in a file-object to gzip, I pass in …

Total answers: 3