473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1653

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sang park | last post by:
Hi all - Just started learning Python this past week and had a question about using the lists in python with objects. (code attached below). basically, what i want to do is read an xml file,...
0
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
7
by: beliavsky | last post by:
Ideally, one can use someone's C++ code by just looking at the header files (which should contain comments describing the functions in addition to function definitions), without access to the full...
2
by: David Dürrenmatt | last post by:
Hi. If I try to use decompyle (decompyle-2.3) for pyc-files < version 2.0, I get an error with marshal_20 (ImportError: dynamic module does not define init function (initmarshal_20) )....
5
by: John Nagle | last post by:
This bug, " robotparser interactively prompts for username and password", has been open since 2003. It killed a big batch job of ours last night. Module "robotparser" naively uses "urlopen" to...
14
by: Ivan Voras | last post by:
Hi, I'm looking for a construct that's similar to (Turbo) Pascal's "with" statement. I read about the Python's new "with" statement, but I was dissapointed to learn that it does something...
92
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming...
3
by: bsagert | last post by:
After a couple of weeks studying Python, I already have a few useful scripts, including one that downloads 1500 Yahoo stock quotes in 6 seconds. However, many things are puzzling to me. I keep on...
2
by: chardish | last post by:
Hello, I'm trying to find out in a script where the location of the current python is. (I'm writing an installer script in python for a simple server application, so i'm going to do a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.