python unzip: os.popen3("unzip ...") or import zipfile?

R

Rocky Zhou

python unzip

At first, I tried to use 'os.popen3("unzip ...") like this:
fin, fout, ferr = os.popen3("unzip -o -d %s %s" % (dest, zipfile))
strerr = ferr.read()
# This makes the program hanging up
if strerr:
print >> sys.stderr, strerr
outlog.error(strerr)

I want to know is this caused by the 'unzip' command does not print
'EOF'? or any other reasons?

At last I did this to do 'unzip':
import zipfile
def _extract_all(self, destdir):
namelist = self.namelist()
namelist.sort()
for name in namelist:
if name.endswith('/'):
print name
os.mkdir(os.path.join(destdir, name))
else:
outfile = open(os.path.join(destdir, name), 'wb')
outfile.write(self.read(name))
outfile.close()
zipfile.ZipFile.extract_all = _extract_all

def unzip(...):
zipo = zipfile.ZipFile(zipfn, 'r')
zipo.extract_all(dest)

But I still want to know the reason why can't os.popen3("unzip ...")
be used.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,181
Latest member
RexGreenwa
Top