[Python-ideas] pathlib suggestions

Todd toddrjen at gmail.com
Wed Jan 25 11:15:40 EST 2017


On Wed, Jan 25, 2017 at 11:04 AM, Thomas Kluyver <thomas at kluyver.me.uk>
wrote:

> On Wed, Jan 25, 2017, at 03:54 PM, Todd wrote:
>
> Those [.tar.foo] are just examples that I encounter a lot, there can be
> other cases where multiple extensions are used.
>
>
> The real issue is that there's no definition of what an extension is. You
> can have dots anywhere in a filename, and it's not at all unusual for them
> to be used before the bit we recognise as the extension. Almost every
> package on PyPI has files named like 'pip-9.0.1.tar.gz', but '.0.1.tar.gz'
> clearly doesn't make any sense as an extension. Without a good definition
> of what the 'full extension' is, we can't have code to find it.
>
> Thomas
>
>

Right, that is why we would have three properties

1. suffix: gets the part after the last period as a string, including the
period (already exists), so "spam.tar.gz" -> ".gz"
2. fullsuffix: gets the part after the first period as a string, including
the period (this is what I am proposing), so "spam.tar.gz" -> ".gz"
3. suffixes: gets the part after the first period as a list of strings
split on the leading period, each including the leading period (already
exists), so "spam.tar.gz" -> [".tar", ".gz"]

"suffix" is only useful if you are sure only the part after the last period
is useful, "fullsuffix" is only useful if you are sure the entire part
after first period is useful, and "suffixes" is needed in more complicated
situations.  This is similar in principle to having "str.split",
"str.rsplit", "str.partition", and "str.rpartition".  pathlib currently has
the equivalent of "str.split" (suffixes) and "str.rpartition" (suffix), but
lacks the equivalent of "str.partition" (fullsuffix).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170125/5df8b3c0/attachment.html>


More information about the Python-ideas mailing list