[Python-ideas] New explicit methods to trim strings
p.f.moore at gmail.com
Mon Apr 1 03:20:03 EDT 2019
On Mon, 1 Apr 2019 at 01:01, Steven D'Aprano <steve at pearwood.info> wrote:
> 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.:
> 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()
In order to support duck typing can I suggest that we also add
These will do the obvious thing, so they do not need documenting.
Obviously only needed for Python 3.x, as in 2.x people never use
variables that may sometimes be strings and sometimes bytes.
*wink* (although the joke is obvious, and so should not need documenting :-P)
More information about the Python-ideas