[Python-ideas] New explicit methods to trim strings
jfine2358 at gmail.com
Mon Mar 25 09:51:31 EDT 2019
Here, concisely, is my view of the situation and my preferences. Mostly, I
won't give supporting arguments or evidence.
We can TRUNCATE either PRE or the POST, and similarly SUBTRACT.
SUBTRACT can raise a ValueError.
TRUNCATE always returns a value.
Interactive examples (not tested)
>>> from somewhere import post_subtract
>>> sub_ed = post_subtract('ed')
Can be 'combined into one'
1. Allow pre_truncate('app', 'applet'), perhaps with different spelling.
2. Allow '-' as a symbol for subtract. (Likely to be controversial.)
I'm not particularly attached to the names. But I definitely think
3. None of these are string methods. (So pure Python implementation
4. Encourage a 'two-step' process. This allow separation of concerns, and
encourage good names.
When we write
the suffix has a special meaning. For example, it's the header. So in one
module define and test a routine remove_header. And in another module use
remove_header. That way, the user of remove_header only needs to know the
business purpose of the command. And the implementer needs to know only the
value of the header.
If the specs change, and the implementer needs to use regular expressions,
then this does not affect the user of remove_header.
I hope this helps. Maybe others would like to express their preferences.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas