feature request: a better str.endswith
daniel.dittmar at sap.com
Fri Jul 18 14:14:15 CEST 2003
Michele Simionato wrote:
> I often feel the need to extend the string method ".endswith" to
> tuple arguments, in such a way to automatically check for multiple
> endings. For instance, here is a typical use case:
> if filename.endswith(('.jpg','.jpeg','.gif','.png')):
> print "This is a valid image file"
In your special case:
if os.path.splitext (filename)  in ['.jpg','.jpeg','.gif','.png']:
print "This is a valid image file"
perhaps even os.path.splitext (filename) .lower ()
for filesystems that are not case sensitive.
More information about the Python-list