[Python-ideas] Small enhancement to os.path.splitext
Tarek Ziadé
ziade.tarek at gmail.com
Tue Apr 20 18:10:27 CEST 2010
On Tue, Apr 20, 2010 at 5:48 PM, Bruce Leban <bruce at leapyear.org> wrote:
> When would you know in advance you want 2 parts? Compare file.tar.gz to
> backup.2010.04.20.tar. I'd think the usual case would be
>
> split
> if gz or zip or...:
> split again
Right, that's from the user point of view, and that's why I was
thinking about numext in the first place,
to be able to do what you describe (a loop with a split position that moves)
my undertsanding now is that we would need to iterate from the
longest-match to the shortest-match,
until we find a pattern that works, so numext should be done from the
left to the right.
Or maybe simply drop that idea and just use path.endswith(extension)... :)
In that case the only subtle case is when the filename starts with '.',
So what about a new API :
os.path.hasext(path, extensions)
That would return True if the path match on extension provided in the
extensions sequence
(using .endswith, but ignoring the first dot if the filename starts with a dot)
Tarek
--
Tarek Ziadé | http://ziade.org
More information about the Python-ideas
mailing list