[ python-Feature Requests-1491485 ] str.startswith/endswith could take a tuple?
SourceForge.net
noreply at sourceforge.net
Wed Jun 7 23:11:39 CEST 2006
Feature Requests item #1491485, was opened at 2006-05-19 10:24
Message generated for change (Comment added) made by gbrandl
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1491485&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tom Lynn (tlynn)
Assigned to: Georg Brandl (gbrandl)
Summary: str.startswith/endswith could take a tuple?
Initial Comment:
In the same way that exceptions can have a tuple of
types specified and isinstance can take a tuple of
types, str.startswith and endswith could take a tuple
of possible prefixes/suffixes.
One use-case::
if filename.endswith(('jpg', 'gif', 'png')):
# ...
vs:
if (filename.endswith('jpg') or filename.endswith
('gif') or
filename.endswith('png')):
#...
Obviously it's not a huge improvement in clarity, but
it does seem to be an improvement to me.
----------------------------------------------------------------------
>Comment By: Georg Brandl (gbrandl)
Date: 2006-06-07 21:11
Message:
Logged In: YES
user_id=849994
I will, tomorrow.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2006-06-06 00:30
Message:
Logged In: YES
user_id=80475
Georg, would you like to implement this one?
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2006-06-05 16:33
Message:
Logged In: YES
user_id=80475
The previous comment was just information. I am +1 on the
proposal because the use case is so common and the proposed
form is concise, clear, and natural.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2006-05-19 20:58
Message:
Logged In: YES
user_id=80475
FWIW, in Py2.5, this would be written:
if any(filename.startswith(s) for s in suffixes):
. . .
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1491485&group_id=5470
More information about the Python-bugs-list
mailing list