[Python-ideas] New explicit methods to trim strings

Steven D'Aprano steve at pearwood.info
Sun Mar 31 19:59:50 EDT 2019


On Mon, Apr 01, 2019 at 12:02:25PM +1300, Greg Ewing wrote:
> Dan Sommers wrote:
> 
> >without_prefix
> >without_suffix
> >
> >They're a little longer, but IMO "without" helps
> >reenforce the immutability of the underlying string.
> 
> We don't seem to worry about that distinction for other
> string methods, such as lstrip and rstrip.

Perhaps we ought to. In the spirit of today's date, let me propose 
renaming existing string methods to be more explicit, e.g.:

str.new_string_in_uppercase
str.new_string_with_substrings_replaced
str.new_string_filled_to_the_given_length_with_zeroes_on_the_left
str.new_string_with_character_translations_not_natural_language_translations

The best thing is that there will no longer be any confusion as to 
whether you are looking at a Unicode string or a byte-string:

    a = a.new_string_trimmed_on_the_left()
    a = a.new_bytes_trimmed_on_the_left()

*wink*



-- 
Steven


More information about the Python-ideas mailing list