473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

reading from an a gzip file

Hello,

I have a gzip file and I try to read from this file withe the next
statements:

gunziped_file = gzip.GzipFile('gzip-file')
input_file = open(gunziped_file,'r')

But I get the nezt error message:

Traceback (most recent call last):
File "read_sfloc_files.py", line 131, in ?
input_file = open(gunziped_file,'r')
TypeError: coercing to Unicode: need string or buffer, instance found

I think that I do some mistake. Would some body tell me what is my
mistake?

Nader
Jun 27 '08 #1
1 2157
Nader wrote:
Hello,

I have a gzip file and I try to read from this file withe the next
statements:

gunziped_file = gzip.GzipFile('gzip-file')
input_file = open(gunziped_file,'r')

But I get the nezt error message:

Traceback (most recent call last):
File "read_sfloc_files.py", line 131, in ?
input_file = open(gunziped_file,'r')
TypeError: coercing to Unicode: need string or buffer, instance found

I think that I do some mistake. Would some body tell me what is my
mistake?

Nader
gzip.GzipFile() creates a file-like object. You don't call open() on it;
you use it directly.

$ echo foo >test
$ gzip test
$ python
>>import gzip
gfh = gzip.GzipFile('test.gz', 'rb')
gfh.read()
'foo\n'
>>gfh.close()
--
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bmgz | last post by:
I am having problems trying to use the gzip module, I do the followig >>>import gzip >>>file = gzip.GzipFile("testfile.txt") >>>file.write() -which params does this accept?, archive name? I...
3
by: rohisingh | last post by:
I have a tar file. The content of the file are as following. rohits@sandman 12-08-04 $ tar tvf 20041208.tar drwxr-xr-x root/root 0 2004-12-08 21:39:19 20041208/ -rw-r--r-- root/root ...
1
by: Yoda Pugsley | last post by:
Hello, I need to read the name of a file inside a .gz. I know it should be the zipped name - .gz, but the filenames are long and truncated sometimes. In perl, what is the command to read the...
24
by: Xah Lee | last post by:
suppose i'm calling two system processes, one to unzip, and one to “tail” to get the last line. How can i determine when the first process is done? Example: subprocess.Popen(); ...
14
by: Bill | last post by:
I've written a small program that, in part, reads in a file and parses it. Sometimes, the file is gzipped. The code that I use to get the file object is like so: if filename.endswith(".gz"):...
11
by: arnaudk | last post by:
I have a large number of sequentially-named zip files, each containing a single csv data file which I need to read into my C++ program. 1) Does anybody know of any open source libraries to handle...
1
by: Nader | last post by:
Hello, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt...
0
by: Gabriel Genellina | last post by:
En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <Ron.Barak@lsi.com> escribi: Note *where* the exception is raised. Until something is actually read, no check is made for the file format. --...
0
by: Barak, Ron | last post by:
Thanks Gabriel, Okay, I get it: I was under the impression that the format check would be done on the open. Bye, Ron. -----Original Message----- From: Gabriel Genellina Sent: Thursday,...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.