Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check if file is txt python

Assuming m is a string, you can use endswith:

if m.endswith('.mp3'):
...
elif m.endswith('.flac'):
...
To be case-insensitive, and to eliminate a potentially large else-if chain:

m.lower().endswith(('.png', '.jpg', '.jpeg'))
Comment

PREVIOUS NEXT
Code Example
Python :: how to take input for list in one line in python 
Python :: python plot two lines with different y axis 
Python :: turn python script into exe 
Python :: How to select parts of a numpy array 
Python :: numpy rolling average 
Python :: python text input 
Python :: string remove in python 
Python :: how to display values on top of bar in barplot seaborn 
Python :: how to for loop for amount in list python 
Python :: legend matplotlib 
Python :: python datetime 
Python :: python for/else 
Python :: python integer to string 
Python :: add new row to numpy array 
Python :: python array methods 
Python :: python venv flask 
Python :: pandas reset index 
Python :: file manage py line 17 from exc django 
Python :: input in one line python 
Python :: python last 3 list elements 
Python :: remove item list python 
Python :: python index 2d array 
Python :: python thread with return values? 
Python :: python how to turn a word into a list 
Python :: pandas melt() function, change the DataFrame format from wide to long 
Python :: pandas remove outliers 
Python :: python pop 
Python :: adding text cv2 
Python :: python str contains word 
Python :: Using mapping in Converting categorical feature in to numerical features 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =