title: Exception handling, only accept specific file inputs
body: <p>This is a bit above my pay grade, so I thought I would ask on here. </p>
  
  <p>My simple Python code prompts the user to enter the name of a file. However, it must be a specific type of file, or else I would like to throw an error. In this case, the files entered must be a text or CSV file, i.e. filename extensions must be <code>.txt</code> or <code>.csv</code></p>
  
  <pre><code>filename = raw_input("Please enter .txt or .csv file: ")
  </code></pre>
  
  <p>I have no idea how to test for that. You begin with something like</p>
  
  <pre><code>def fileName():
     while True:
         try: 
             filename = raw_input("Please enter .txt or .csv file: ")
  </code></pre>
  
  <p>and then use an if statement check whether the last four characters are <code>.txt</code> or <code>.csv</code>. </p>
  
  <p>What is the standard way to do this?</p>