[Python-ideas] New explicit methods to trim strings
steve at pearwood.info
Sat Mar 30 08:41:06 EDT 2019
On Sat, Mar 30, 2019 at 11:40:18AM +0000, Paul Moore wrote:
> Is str.trim like str.swapcase, or like str.split? Who knows, at this point?
I think you are making a rhetorical point, but not a very good one. I
think we all know, or at least *should* know, that this proposal is much
closer to split than swapcase.
Most of us have had to cut a prefix or a suffix from a string, often a
file extension. Its not as common as, say, stripping whitespace, but it
happens often enough.
Stackoverflow and the mailing lists and even the bug tracker are full of
people asking about "bugs" in str.[lr]split because they've tried to use
those methods to cut prefixes and suffixes, so we know that this
functionality is needed far more often than swapcase, and easy to get it
We can't say the same about swapcase. Even in Python 1.5, it was a
gimmick. I can only think of a single use-case for it:
"I've typed a whole lot of text without noticing that Caps Lock
was on, so it looks like 'hELLO wORLD' by mistake."
> try to make the proposer consider whether while his idea seems
> great right now, will it feel more like str.swapcase in a few years? And
> sometimes that pushback *is* too conservative, and an idea is good. But it
> still needs someone to implement it, document it, and integrate it into the
> language - the proposer isn't always able (or willing) to do that, so again
> there's a question of who does the work?
And that's a very good point -- if there's no volunteer willing and able
to do the work, even the best ideas can languish, sometimes for years.
But that's not a reason to *reject* an idea.
More information about the Python-ideas