I need to process a .gz file with Python.
I pass the filename into my Python script with:
infile = sys.argv[1]
with gzip.open(infile, 'rb') as f:
logfile = f.read()
which gives me:
with gzip.open(infile, 'rb') as f:
AttributeError: GzipFile instance has no attribute '__exit__'
If I manually gunzip my .gz file and then pass that to my Python script, all works fine.
logfile = open(infile, 'r').read()
NB: I'm using Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37). I don't have the ability to update Python on this computer. How can I process a gzipped text file with Python 2.6?