title: Cannot write to a file (new file is blank after writing to it)
body: <p>I am trying to create a .py file from a .py file and then run the newly created .py file.  The problem is, after creating the file from my original file, when I open the new file, there is literally nothing in the file.  Here is my code:</p>
  
  <pre><code>bfile = open("browsertask.py", "w+")
  print('success')
  bfile.write("from selenium import webdriver")
  print('success2')
  bfile.write("driver.get('" + link + "')")
  print('success3')
  os.system('python browsertask.py')
  </code></pre>
  
  <p>(the variable <code>link</code> was defined before in the program)</p>
  
  <p>The code runs without raising any errors.  When I check the newly created file to see if the text was written to the file, there is nothing in the file.  I researched this and I do not think I am doing anything incorrect.</p>
  
  <p>Does anyone know what I am doing wrong here?</p>
  
  <p>EDIT:  Thanks to the users in the comments telling me to close the file before running, this actually fixed the problem!</p>
  
  <p>EDIT:  I don't know how to mark my question as answered, I tried answering it myself and accepting that answer but I have to wait two days.</p>