linux - How to use subprocess to unzip gz file in python -


i dont know how unzip gz file in python using subprocess.

gzip library slow , thinking make same function above using gnu/linux shell code , subprocess library.

def __unzipgz(filepath):   import gzip    inputfile   =   gzip.gzipfile(filepath, 'rb')   stream      =   inputfile.read()   inputfile.close()    outputfile  =   file(os.path.splitext(filepath)[0], 'wb')   outputfile.write(stream)   outputfile.close() 

you can use this:

import subprocess  filename = "some.gunzip.file.tar.gz" output = subprocess.popen(['tar', '-xzf', filename]) 

since there no useful output here, use os.system instead of subprocess.popen this:

import os  filename = "some.gunzip.file.tar.gz" exit_code = os.system("tar -xzf {}".format(filename)) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -