[Tutor] zip question

Alberto Troiano albertito_g at hotmail.com
Tue May 10 15:00:30 CEST 2005


The problem is that you have to get the content before you can get the 
filename or comment of the files.
You have to do something like this

import zipfile
file=zipfile.ZipFile("yourfile.zip")
f=file.getinfo(name_of_the_file_inside_yourfile.zip)


And then you can take the comments and filenames you want with
f.comment
f.filename

Copy and paste without parenthesis. The getinfo part, You have to get the 
name of the files inside.
I did a program to put the name of the files inside the zip in a list and 
then I looped inisde the list with the commands I'm sending you

Regards

Alberto


>From: jfouhy at paradise.net.nz
>To: Python tutor <tutor at python.org>
>Subject: Re: [Tutor] zip question
>Date: Tue, 10 May 2005 13:19:52 +1200 (NZST)
>
>Quoting "D. Hartley" <denise.hartley at gmail.com>:
>
> > Instances have the following attributes:
> >
> > filename, comment, etc.
> >
> >
> > I've tried about ten things to get "filename" to work:
> >
> > myzip.filename("99905.txt") (str not callable)
>
>Check out the error message: "str not callable".  You are trying to call
>something whose type is "str" --- ie: a string.  In python, there is no
>distinction between callable and noncallable attributes.
>
>try:
> >>> print myzip.filename
>It should print the filename that this ZipInfo object refers to.
>
>Likewise, myzip.comment is a string which is the comment attached to the 
>file in
>the zip.
>
>If you have any background in other languges, it might help you to think of
>these as "member variables" (or whatever they call them).  And a ZipInfo 
>object
>appears to be similar to a struct in C/C++.
>
>I hope this helps.
>(and if it doesn't, the fault is probably in the explanation, so keep 
>asking,
>and I (or someone else) will try again :-) )
>
>--
>John.
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor


Gaucho




More information about the Tutor mailing list