[Python-ideas] New explicit methods to trim strings

David Mertz mertz at gnosis.cx
Mon Apr 1 22:28:44 EDT 2019

On Mon, Apr 1, 2019 at 10:11 PM Dan Sommers <
2QdxY4RzWzUUiLuE at potatochowder.com> wrote:

> So I've seen someone (likely David Mertz?) ask for something
> like filename.strip_suffix(('.png', '.jpg')).  What is the
> context?  Is it strictly a filename processing program?  Do
> you subsequently have to determine the suffix(es) at hand?

Yes, I've sometimes wanted something like "the basename of all the graphic
files in that directory."  But here's another example that is from my
actually current job:

I do machine-learning/data science for a living. As part of that, I
generate a bunch of models that try to make predictions from the same
dataset.  So I name those models like:


I would like to answer the question "What types of models have I tried
against the datasets?"  Obviously, I *can* answer this question.  But it
would be pleasant to answer it like this:

styles = {model.lstrip(('dataset1', 'dataset2'))
               .rstrip(('gz', 'xz', 'zip', 'bz2))

          for model in models}

That's something very close to code I actually have in production now.

Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190401/0742c2e3/attachment.html>

More information about the Python-ideas mailing list