title: os.rename() fails, in use by another process
body: <p>So I'm trying to rename a file, and it keeps saying "The process cannot access the file because it is being used by another process." But I know it's not being used by another process so I'm not sure what's going on. Here's my code</p>
  
  <pre><code>while self.fileSet.hasMoreFiles():
      file = self.fileSet.nextFile()
      periodIndex=file.find(".")
      extension = file[periodIndex:]
      baseName=file[:periodIndex]
      self.newFile=open(file, 'w+')
      self.backupName = baseName + "_bak" + extension
      os.rename(file, baseName + "_bak" + extension)
      self.newFile=open(file, 'w+')
      self.writeNew()
  </code></pre>