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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rocky Zhou

    #1

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

    python unzip

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

    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(se lf, destdir):
    namelist = self.namelist()
    namelist.sort()
    for name in namelist:
    if name.endswith('/'):
    print name
    os.mkdir(os.pat h.join(destdir, name))
    else:
    outfile = open(os.path.jo in(destdir, name), 'wb')
    outfile.write(s elf.read(name))
    outfile.close()
    zipfile.ZipFile .extract_all = _extract_all

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

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

    Thanks.

Working...