[Tutor] Zipfile and File manipulation questions.

Kent Johnson kent37 at tds.net
Sun Oct 15 00:33:05 CEST 2006


Chris Hengge wrote:
> 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

With Python 2.5 you can do this with a tuple argument. You need an extra 
set of parentheses to create the tuple:
if filename.endswith(('.cap','.fru','.hex', '.sdr', '.cfg')):

In Python 2.4 or less you need a separate endswith() for each ending.

Kent



More information about the Tutor mailing list