I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like
filename = '/home/lancaster/Downloads/a.ppt'
extention = filename.split('/')[-1]
The role of a file extension is to tell the viewer (and sometimes the computer) which application to use to handle the file.
Taking your worst-case example in your comments (
a.ppt.tar.gz), this is a PowerPoint file that has been tar-balled and then gzipped. So you need to use a gzip-handling program to open it. Using PowerPoint or a tarball-handling program wouldn't work. OK, a clever program that knew how to handle both
.gz files could understand both operations and work with a
.tar.gz file - but note that it would do that even if the extension was simply
The fact that both
gzip add their extensions to the original filename, rather than replace them (as
zip does) is a convenience. But the base name of the gzip file is still