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

Discussion in 'Python' started by Rocky Zhou, Apr 2, 2007.

  1. Rocky Zhou

    Rocky Zhou Guest

    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.
    Rocky Zhou, Apr 2, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C B
    Replies:
    4
    Views:
    4,549
    Chris Uppal
    Nov 10, 2004
  2. Mark Wondratschek

    Python zipfile: Zip empty directories.

    Mark Wondratschek, Aug 29, 2003, in forum: Python
    Replies:
    2
    Views:
    612
    Mark Wondratschek
    Sep 1, 2003
  3. Replies:
    2
    Views:
    563
  4. Pierre Rouleau
    Replies:
    2
    Views:
    498
    Pierre Rouleau
    Dec 12, 2006
  5. Jason Friedman

    python zipfile v. native unzip

    Jason Friedman, Jan 31, 2012, in forum: Python
    Replies:
    0
    Views:
    150
    Jason Friedman
    Jan 31, 2012
Loading...

Share This Page