Answers for "how to read file in python and check data in the file"

0

python read entire file

with open('Path/to/file', 'r') as content_file:
    content = content_file.read()
Posted by: Guest on March-07-2020
0

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'))
Posted by: Guest on May-06-2021

Code answers related to "how to read file in python and check data in the file"

Python Answers by Framework

Browse Popular Code Answers by Language