我需要用Python处理一个.gz文件。
我使用以下代码将文件名传递给Python脚本:
infile = sys.argv[1]
with gzip.open(infile, 'rb') as f:
logfile = f.read()
这给了我:
with gzip.open(infile, 'rb') as f:
AttributeError: GzipFile instance has no attribute '__exit__'
如果我手动解压缩.gz文件,然后将其传递给我的Python脚本,一切都正常工作。
logfile = open(infile, 'r').read()
注意:我使用的是Python 2.6.6(r266:84292,2016年8月18日,15:13:37)。我没有权限在这台计算机上更新Python。我该如何使用Python 2.6处理一个gzipped文本文件?