gzip - Python Fileinput openhook=fileinput.hook_compressed syntax use -
i'm trying open number of files using glob , feed them through series of functions. of files gziped bz2 , plain text. used fileinput typically can't figure out syntax have take in compressed files. based on python fileinput doc should like:
openhook=fileinput.hook_compressed my code looks like:
import fileinput import glob filestobeanalyzed = glob.glob('./files/*') filename in filestobeanalyzed: inputfilename = filename line in fileinput.input([inputfilename, openhook=fileinput.hook_compressed]): #do stuff i invalid syntax on fileinput line @ = sign.
any suggestions?
you want
for line in fileinput.input(inputfilename, openhook=fileinput.hook_compressed): #do stuff (i removed square brackets). trying assignment in list constructor. e.g.
my_list=["foo",bar="baz"] #this doesn't work (syntaxerror) you got idea python documentation uses [ , ] indicate optional arguments functions.
this aside -- there more information in traceback can pin down problem type of error , line number. (read: when have traceback, it's appreciated if paste whole thing can see it)
Comments
Post a Comment