I'm trying fileinput to read some compressed files, and I tried the following three methods, however, none of them really works.
file=os.join.path(path+filename)
for i,line in enumerate(fileinput([file], openhook=gzip.open)):
for i,line in enumerate(fileinput.input(openhook=fileinput.hook_compressed(file1,'r'))):
for i,line in enumerate(fileinput.FileInput(openhook=fileinput.hook_compressed(file1,'r'))):
For the first command, errors are like:
'module' object is not callable
For the third command, errors like:
Traceback (most recent call last):
File "read_file.py", line 15, in <module>
for i,line in enumerate(fileinput.input(openhook=fileinput.hook_compressed(file1,'r'))):
File "/share/lib/python2.6/fileinput.py", line 103, in input
_state = FileInput(files, inplace, backup, bufsize, mode, openhook)
File "/share/lib/python2.6/fileinput.py", line 230, in __init__
raise ValueError("FileInput openhook must be callable")
ValueError: FileInput openhook must be callable
I don't understand why openhook cannot be callable here?
Can anyone help me with this? thx