r/Python • • Sep 15 '20

Resource Python 3.9: All You need to know 👊

https://ayushi7rawat.hashnode.dev/python-39-all-you-need-to-know
1.2k Upvotes

204 comments sorted by

View all comments

Show parent comments

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.

3

u/Brian Sep 16 '20

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.

1

u/yad76 Sep 16 '20

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.

1

u/Ph0X Sep 15 '20

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.

3

u/yad76 Sep 15 '20

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.