title: Is this the best way to get unique version of filename w/ Python?
body: <p>Still 'diving in' to Python, and want to make sure I'm not overlooking something. I wrote a script that extracts files from several zip files, and saves the extracted files together in one directory. To prevent duplicate filenames from being over-written, I wrote this little function - and I'm just wondering if there is a better way to do this?
  Thanks!</p>
  
  <pre><code>def unique_filename(file_name):
  counter = 1
  file_name_parts = os.path.splitext(file_name) # returns ('/path/file', '.ext')
  while os.path.isfile(file_name): 
      file_name = file_name_parts[0] + '_' + str(counter) + file_name_parts[1]
      counter += 1
  return file_name
  </code></pre>
  
  <p>I really <em>do</em> require the files to be in a single directory, and numbering duplicates is definitely acceptable in my case, so I'm not looking for a more robust method (tho' I suppose any pointers are welcome), but just to make sure that what this accomplishes is getting done the right way.</p>