python get file ending 1

python get file ending

import os
# creates a tuple.
# fn contains the filename, in this case abc
# fend contains the file ending, in this case .txt
fname, fend = os.path.splitext("/Users/pankaj/abc.txt")

Here is what the above code is Doing:
1. os.path.splitext() splits the filename into two parts.
2. The first part is the filename, and the second part is the file extension.
3. The first part is stored in the variable fname, and the second part is stored in the variable fend.

Similar Posts