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.
Yeah, good point. I was focusing just on the double extension case that was cited. Looks like the pathlib and os.path implementations are just doing and rfind for . and then compensating for the case where it might be at the beginning.
Yes, that's what my code does but I didn't specify that. It could be that in your use case, you need the filename without any extensions. Again, you need to see what your specific input and output is.
Yeah, but I think your implementation is the sane behavior for any default implementation. `os.path`, `pathlib`, etc. are all going to treat just `.gz` as the extension as they should.
7
u/yad76 Sep 15 '20
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.