[Tutor] zip question
D. Hartley
denise.hartley at gmail.com
Tue May 10 02:26:54 CEST 2005
P.S. I realize that zipfile has commands, and zipinfo only seems to
list "attributes." Each instance of ZipInfo is a collection of
information about the file in the archive: its filename, its comments,
etc. So filename is not filename() - it's not a callable command. But
how can i access/see this information about a given member of the
archive?
On 5/9/05, D. Hartley <denise.hartley at gmail.com> wrote:
> This is a problem I'm having with instances of classes and their
> objects. John suggested:
>
> > Look at the constructor :-)
> >
> > >>> import zipfile
> > >>> z = zipfile.ZipFile('myzip.zip')
> > >>> z.printdir()
>
> I admitted that my grasp of classes (and "constructors") is a bit
> fuzzy. I did get this particular class to work, and got the first half
> of the problem done. However, now i'm working in another class,
> zipinfo. It says:
>
> Instances of the ZipInfo class are returned by the getinfo() and
> infolist() methods of ZipFile objects. Each object stores information
> about a single member of the ZIP archive.
>
> 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)
> myzip.comment(file("99905.txt")) (no file with this name - i suppose,
> if it's still zipped?)
>
> myzip.getinfo(99905.txt) (invalid syntax)
>
> and, trying to do this one the same way as the zipfile one (a long shot):
> mynote = zipfile.ZipInfo("channel.zip")
> >>> mynote
> <zipfile.ZipInfo instance at 0x0174CB48>
> mynote.filename(file("99905.txt")) (again, no such file name)
>
> i know this trial-and-error method is sloppy, trying to find the right
> format, but i'm still getting used to dot notations and modules and
> classes and so on - was trying to figure out a way to make it work
> without having to ask and feel dumb, ha ha.
>
> Does anyone have a (hopefully simple) explanation of how to format
> this command? I'd really appreciate it!
>
> Thanks,
> Denise
>
More information about the Tutor
mailing list