Discussion:
Extracting .zip files with Python
Ray Parrish
2010-03-06 04:14:12 UTC
Permalink
Hello,

Here I am stuck again... 8-) Here's my code as ran in the interpreter,
and the errors -
ThisZip = zipfile.ZipFile("/home/ray/logs/IIS/ex100102.zip", "r")
List = ThisZip.namelist()
List[0]
'ex100102.log'
ArchiveName = List[0]
ThisZip.extract(ArchiveName,"/home/ray/logs/IIS/" + ArchiveName)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: ZipFile instance has no attribute 'extract'
FileHandle = ThisZip.open(ArchiveName,"r")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: ZipFile instance has no attribute 'open'

I think the documents actually said that .extract() was a Python 2.6
thing, and since I'm on Python 2.5 I guess it doesn't have that, but it
should have .open() as it was listed above the 2.6 version seperation in
the docs.

Can you please tell me what I'm doing wrong, and give me some pointers
on extracting .zip files with the Python zipfile class?

Thanks, Ray Parrish
--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com
Marius Gedminas
2010-03-06 15:13:16 UTC
Permalink
Post by Ray Parrish
Here I am stuck again... 8-) Here's my code as ran in the interpreter,
and the errors -
ThisZip = zipfile.ZipFile("/home/ray/logs/IIS/ex100102.zip", "r")
...
Post by Ray Parrish
ThisZip.extract(ArchiveName,"/home/ray/logs/IIS/" + ArchiveName)
...
Post by Ray Parrish
AttributeError: ZipFile instance has no attribute 'extract'
FileHandle = ThisZip.open(ArchiveName,"r")
...
Post by Ray Parrish
AttributeError: ZipFile instance has no attribute 'open'
I think the documents actually said that .extract() was a Python 2.6
thing, and since I'm on Python 2.5 I guess it doesn't have that, but it
should have .open() as it was listed above the 2.6 version seperation in
the docs.
http://docs.python.org/library/zipfile.html?highlight=zipfile#zipfile.ZipFile.open
says "New in version 2.6".
Post by Ray Parrish
Can you please tell me what I'm doing wrong, and give me some pointers
on extracting .zip files with the Python zipfile class?
Use ThisZip.read(filename) to get the contents as a Python string, then
write it out to a file.

Marius Gedminas
--
As a rule of thumb, I reckon Python to be an order of magnitude more wasteful
of CPU cycles and memory than my favourite low-level language, C++.
-- Thomas Guest
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20100306/295359d4/attachment.pgp>
Continue reading on narkive:
Loading...