Answers for "how to check file extension in python"

3

python check file extension

# Checking for single extension (.txt) of file
if file.endswith(".txt"):
  # do something
  
# Checking multiple extensions (.txt, .pdf, .mp3, ...)
if file.endswith((".txt", ".pdf", ".mp3")):
  # do something
Posted by: Guest on November-04-2020
1

simple way of finding file extension python programming

file = input("Which file did you opend last time user:- ")
extenction = file.split(".")
print("humm so last time you opened file extenction was .",extenction[1])
Posted by: Guest on July-26-2021
0

how to get what type of file a file is in python

import os

# unpacking the tuple
file_name, file_extension = os.path.splitext("/Users/pankaj/abc.txt")

print(file_name)
#returns abc
print(file_extension)
#returns .txt
Posted by: Guest on August-28-2020

Code answers related to "how to check file extension in python"

Python Answers by Framework

Browse Popular Code Answers by Language