[Tutor] scratching my head

Steven D'Aprano steve at pearwood.info
Mon Aug 3 02:56:18 CEST 2015


On Sun, Aug 02, 2015 at 11:46:31PM +0100, Alan Gauld wrote:
> On 02/08/15 23:01, Alan Gauld wrote:
> 
> >found = False
> >for s in (".jpg",".png",".avi",".mp4"):
> >     found = test or (s in file.lower())
> 
> Oops, that should be:
> 
> found = found or (s in file.lower())

extensions = (".jpg",".png",".avi",".mp4")
found = any(s in filename.lower() for s in extensions)

but that's still wrong, because it will find files like

    History.of.Avis.PA.pdf

as if it were an AVI file. Instead, use os.path.splitext.



-- 
Steve


More information about the Tutor mailing list