I want to make a program that checks whether a file (path) contains text that can be "printed."
For example:
interesting = [apple.txt, plane.mov, yeezer.mp3, joker.py]
So apple and joker would be printed, but plane and yeezer would result in an error.
Is there an existing function that I can get to do this or should I just brute force it (check the file type manually to see if it can contain text)?
Edit: I found a solution, just use try/except. If trying open(path, r) is an error then it's not a text file, if it is not then we can print.