470,647 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

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

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.

Apr 2 '07 #1
0 1530

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sang park | last post: by
reply views Thread by Vio | last post: by
7 posts views Thread by beliavsky | last post: by
2 posts views Thread by David Dürrenmatt | last post: by
5 posts views Thread by John Nagle | last post: by
14 posts views Thread by Ivan Voras | last post: by
92 posts views Thread by ureuffyrtu955 | last post: by
3 posts views Thread by bsagert | last post: by
2 posts views Thread by chardish | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.