[issue34931] os.path.splitext with more dots
Malcolm Smith
report at bugs.python.org
Thu May 28 14:59:05 EDT 2020
Malcolm Smith <malcolm.smith at gmail.com> added the comment:
> Try for example create/rename .somename.jpg file in Ubuntu.
> It is normal image with .jpg extension. You could open it etc.
>
> You can't use standard python splitext() function to detect extension.
Yes you can (Python 3.8.2):
>>> splitext(".somename.jpg")
('.somename', '.jpg')
Only leading dots are treated specially. If there are non-leading dots later in the name, then the filename will be split at the last one.
So the only remaining question is weird filenames like ".....jpg". There's no way to know whether that's supposed to be a name with an extension, or a dot-file with multiple leading dots. Either choice would be reasonable, but we've already gone with the second one.
Maybe sometimes you might prefer the other way, but such filenames are so rare that I can't imagine we'd ever add an option for this. So I think this issue can be closed.
----------
nosy: +Malcolm Smith
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34931>
_______________________________________
More information about the Python-bugs-list
mailing list