My question looks similar to this one but not sure... I want to parse some log files that are sometimes compressed in gzip sometimes not.
I've got the following:
if file[-3:] == ".gz":
with gzip.open(file, 'rb') as f:
# do something
else:
with open(file) as f:
# do the same thing.
Is it possible to have only one with
statement ?