title: Print a returned file from a function
body: <p>I just want to print a file that is returned from a separate function:</p>
  
  <pre><code>def open_file():
      while True:
          try:
              filename = input("Input a file name: ")
              file=open(filename,'r')
              return file
          except FileNotFoundError:
              print("Error: Enter a valid file.")
              continue
          else:
              break
  open_file()
  for line in file:
      print(line)
  </code></pre>
  
  <p>It's prompting for the file, and gives the error and re-promts when an invalid file is entered, but when a valid file is entered, it says that "file" is not defined. It's defined in the open_file function though, and is the returned value... So why doesn't it print?</p>