[Tutor] Zipfile and File manipulation questions.

Chris Hengge pyro9219 at gmail.com
Sun Oct 15 00:18:28 CEST 2006


Oops.... I get an error using that code..

    if filename.endswith('.cap','.fru','.hex') or filename.endswith('.sdr',
'.cfg'):
TypeError: slice indices must be integers or None

On 10/14/06, Bill Burns <billburns at pennswoods.net> wrote:
>
> Chris Hengge wrote:
> > First question..
> >
> > This is the code that I have:
> > for filename in zfile.namelist():
> >         outfile = open(filename, 'w')
> >         outfile.write(zfile.read(filename))
> >         outfile.close()
> >
> > Is there a way to say :
> > for filename in zfile.namelist() contains '.txt, .exe':
> >         outfile = open(filename, 'w')
> >         outfile.write(zfile.read(filename))
> >         outfile.close()
>
>
> Maybe take a look at 'endswith':
>
> Example:
> for filename in zfile.namelist():
>      if filename.endswith('.exe') or filename.endswith('.txt'):
>          # do something with filename
>
>
> > second question is along the same lines..
> >
> > I'm looking for a way to say:
> > os.remove('All by .py')
> >
> > or-
> >
> > os.remove('*.txt, *.exe')
> >
> > Thank you all again for your time and effort.
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061014/483e973e/attachment.htm 


More information about the Tutor mailing list