def py_gunzip(gz_file, outdir = "."):
# extract a .gz file
# read in the contents
print gz_file
print outdir
print "Reading file:\t" + gz_file
input_file = gzip.GzipFile(gz_file, 'rb')
file_contents = input_file.read()
input_file.close()
print "Finished reading file"
# get the output path from the outdir and filename
output_file_base = os.path.basename(os.path.splitext(gz_file)[0])
print output_file_base
output_file_path = os.path.join(outdir, output_file_base)
print output_file_path
# write the contents
print "Writing contents to file:\t" + output_file_path
print type(output_file_path)
# output_file = file(output_file_path, 'wb')
output_file = open(output_file_path, 'wb')
output_file.write(file_contents)
output_file.close()
评论列表
文章目录