title: Detecting for invalid file inputs, Python
body: <p>I have an assignment to write a Python script which "detects whether the file is readable or not". </p>
  
  <p>I am stuck as to which exceptions I should run. Let's say the input file is intended to be a text file, with extension <code>*.txt</code></p>
  
  <p>What is the exception I should raise? I suspect there should be multiple. At the moment, I have:</p>
  
  <pre><code>with open('example_file.txt") as textfile:
          if not textfile.lower().endswith('.txt'):
              raise argparse.ArgumentTypeError(
                  'Not a text file! Argument filename must be of type *.txt')
          return textfile
  </code></pre>
  
  <p>However, that only checks the file extension. What else could I possibly check? What is the standard for file I/O in Python? </p>