It's ambiguous which of the two behaviors is correct in that case, but if you want to remove all extensions, you can just switch to normal split. Of course that will break if it contains a period in the name, but that's also ambiguous. I guess you need a certain level of knowledge about what you're trying to achieve.
I don't think it's ambiguous at all. It is a gzip file and so it has a `.gz` extension and your `rsplit` gets the correct result. The `.tar` is just reflecting the name of the gzipped file and not part of the extension of the current gzip file that we are currently concerned with.
I would agree for that case, but I would say one place where it does give the wrong answer (or at least, a different answer from splitext etc) is with dotfiles. Ie '.config' denotes a hidden file on unix, and pathlib and splitext will treat it as the stem '.config' with empty extension, rather than an empty sten with ".config" suffix.
I don't know for sure, but files can have multiple extension such as file that are in download state that are something.mp4.crowndowload It's just a guess anyway, I think it would usually work
If you want the extension only, this approach fail if you give it a file that doesn't have it for whatever reason, and if you want the name without the extension, doing file_name.split(".")[0] for example fail to consider that there's absolutely nothing stopping you, your user or anything else from using "." in the file name (or path) for whatever reason, for example "my.test.file.txt" is a perfectly valid file name.
Is better to use a function that already have all those things in consideration like os.path.splitext
0
u/[deleted] Sep 15 '20
[deleted]