Skip to content

Instantly share code, notes, and snippets.

Last active May 22, 2018 08:59
What would you like to do?
Unzip gz file if necessary
def unzip_if_necessary(self, filename):
print "unzip_if_necessary: " + filename
f = open(filename)
# Read magic number (the first 2 bytes) and rewind.
magic_number =
if magic_number == '\x1f\x8b':
print "gzip file"
data = ''
# with gzip.GzipFile(fileobj=f) as f:
with, 'rb') as f:
data =
print "Writing to " + filename
with open(filename, "w") as f:
print "csv file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment