Works in Python but Not Jython
kcollins15 at cfl.rr.com
kcollins15 at cfl.rr.com
Fri Dec 6 11:10:58 EST 2002
Hi,
here I have a very simple code snippet to unzip a zip file.
I'm working with Jython 2.1 and Python 2.2. The code works fine running in
python but fails in jython.
Jython is not detecting the os.path.basename(name)check and tries to open
everything in zipfile.
****CODE*****
import zipfile
import os
import string
#open the zipped file and extract the content in c:\
zf =zipfile.ZipFile("C:\\temp\\apache-2_0_39-windows.zip", "r")
if hasattr(zf, 'namelist'):
files = zf.namelist()
#print files
for name in files:
if os.path.basename(name):
newFile = open ('C:/'+name, "wb")
print newFile
newFile.write (zf.read (name))
newFile.close()
else:
print "Making Directory", name
os.makedirs('C:/'+ name)
else:
print "Zip File is empty"
C:\Projects>java org.python.util.jython unzip_python.py
Traceback (innermost last):
File "unzip_python.py", line 12, in ?
IOError: File not found - C:\apache\2.0.39 (The system cannot find the path spec
ified)
I tried changing the jython directory check to a
if os.path.isfile(name):
This fails too, it creates everything as a directory.
PLEASE HELP>
thx
KC
More information about the Python-list
mailing list