On 2019-03-24 08:42, Alex Grigoryev wrote:
Following the discussion here <https://link.getmailspring.com/link/7d84d131-65b6-4ef7-9c43-51957f9df...@getmailspring.com/0?redirect=https%3A%2F%2Fbugs.python.org%2Fissue36410&recipient=cHl0aG9uLWlkZWFzQHB5dGhvbi5vcmc%3D> I propose to add 3 new string methods: str.trim, str.ltrim, str.rtrim Another option would be to change API for str.split method to work correctly with sequences.

In [1]: def ltrim(s, seq):

    ...:     return s[len(seq):] if s.startswith(seq) else s

    ...:


This has a subtle bug:

In [2]: def rtrim(s, seq):

    ...:     return s[:-len(seq)] if s.endswith(seq) else s

    ...:

If len(seq) == 0, then rtrim will return ''.

It needs to be:

def rtrim(s, seq):
    return s[ : len(s) - len(seq)] if s.endswith(seq) else s
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to