Answers for "check file format 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
0

python check file format

# Assuming m is a string, you can use endswith:
if m.endswith('.mp3'):
...
elif m.endswith('.flac'):
...
Posted by: Guest on February-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language