title: NameError using "finally: f.close()" together with "with open(..) as f"
body: <p>I have a code like this below in python.I'm using the 'with' keyword to open a file and parsing it's contents.But the error occurs when I'm trying to close the file.Please help.</p>
  
  <p>Error message:"NameError:name 'f' is not defined"</p>
  
  <pre><code>try:
      user_xml_name = raw_input('Enter the xml name: ')
      xml_name = user_xml_name.replace(" ", "")
  
      with open(xml_name) as f:
          with open("temp_" + xml_name, "w") as f1:
              for line in f:
                  f1.write(line)
  
  except IOError:
      print print "File" + " " + user_xml_name + " " + "doesn't exist"
  
  finally :
      f.close()
      f1.close()
  </code></pre>