By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,971 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,971 IT Pros & Developers. It's quick & easy.

reading from an a gzip file

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.