feature request: a better str.endswith
mis6 at pitt.edu
Sat Jul 19 15:30:37 CEST 2003
Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.1058534669.8794.python-list at python.org>...
> Michele> I often feel the need to extend the string method ".endswith"
> Michele> to tuple arguments, in such a way to automatically check for
> Michele> multiple endings. For instance, here is a typical use case:
> Michele> if filename.endswith(('.jpg','.jpeg','.gif','.png')):
> Michele> print "This is a valid image file"
> This is analogous to how isinstance works, where its second arg can be a
> class or type or a tuple containing classes and types.
> I suggest you submit a feature request to SF. A patch to stringobject.c and
> unicodeobject.c would help improve chances of acceptance, and for symmetry
> you should probably also modify the startswith methods of both types.
Too bad my skills with C are essentially unexistent :-(
More information about the Python-list