title: Make Python wait until a file exists before continuing
body: <p>In my code, I write a file to my hard disk. After that, I need to import the generated file and then continue processing it.</p>
  
  <pre><code>for i in xrange(10):
      filename=generateFile()
      # takes some time, I wish to freeze the program here
      # and continue once the file is ready in the system
      file=importFile(filename)
      processFile(file)
  </code></pre>
  
  <p>If I run the code snippet in one go, most likely <code>file=importFile(filename)</code> will complain that that file does not exist, since the generation takes some time.</p>
  
  <p>I used to manually run <code>filename=generateFile()</code> and wait before running <code>file=importFile(filename)</code>.<br>
  Now that I'm using a <code>for</code> loop, I'm searching for an automatic way.</p>