1

I am trying to insert some data from compressed .gz (gzip) files using Python. These files are in .tsv format. I know how to read gzip compressed files, but I cannot resolve the problem how to insert it not converting to csv format.

I have already tried to read compressed file using below code.

gzip_file = gzip.open(os.path.join(path, filename), 'rb')
file_cont = gzip_file.read()
7
  • that code looks OK, what do you actually want to do? Commented May 3, 2019 at 21:17
  • I want to read each line of this compressed .tsv file and insert it into PostgreSQL table, but I know how it can be done only working on .csv files, but not on compressed .tsv. How can I read each line with attributes using "file_cont" object? I would be so grateful for any advice. Commented May 3, 2019 at 21:22
  • this just functions as a normal file object, so you'd proceed as normal as you would for a CSV file. Postgres COPY FROM allows you to specify a DELIMITER so you might be able to pass data without processing in Python Commented May 3, 2019 at 21:27
  • Yes, it's possbile, but in such case I need to unzip gzip file. The case is I am wondering if it's possible without uzipping gzip file. Commented May 3, 2019 at 21:33
  • And I have to process it using Python. Commented May 3, 2019 at 21:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.