title: Python try except in while loop
body: <pre><code>while True:
      print "Unesite ime datoteke kojoj zelite pristupiti."
      try:
          ime = raw_input("")
          printaj = open(ime, "r")
          print "Ovo su informacije ucenika %s." % (ime)
          print printaj.read()
      except:
          print "Datoteka %s ne postoji." % (ime)
      printaj.close()
  </code></pre>
  
  <p>This program is supposed to look for a file, open and read it if it exists.</p>
  
  <p>So I open program, try to look for a file lets say under name "John" but it doesn't exist so program closes even its in a while loop. When I look for a file and it exists, it's information is printed and my program works as intended. </p>
  
  <p>From there I can look for a file that doesn't exist and it prints out <code>Datoteka %s ne postoji.</code> like I wanted. 
  So problem here is the first file name I look up for in a program.
  If its correct than good... program will function from there.</p>
  
  <p>But if its wrong ... program just closes and you have to open program again.</p>