title: How to pythonically avoid this code duplication with a while loop?
body: <p>I want to find the first filename <code>myfile????.txt</code> that doesn't exist yet (<code>????</code>  is a number). This works:</p>
  
  <pre><code>import os
  i = 0
  f = 'myfile%04i.txt' % i
  while os.path.exists(f):
      i += 1
      f = 'myfile%04i.txt' % i
  </code></pre>
  
  <p>but I don't like the code duplication of <code>f = ...</code>.</p>
  
  <p><strong>Is there a pythonic way to avoid the code duplication in this <code>while</code> loop?</strong></p>
  
  <p>NB: I have posted a half-satisfactory solution, using a <code>do/while</code> idiom, as mentioned in the main answer of <a href="https://stackoverflow.com/questions/743164/emulate-a-do-while-loop-in-python">Emulate a do-while loop in Python?</a>, but I still wonder if there is better way for this particular case (thus, it's not a dupe of this question).</p>