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:
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')
(the variable link
was defined before in the program)
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.
Does anyone know what I am doing wrong here?
EDIT: Thanks to the users in the comments telling me to close the file before running, this actually fixed the problem!
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.