I have been coding a program that opens files and edits them, but for the code to do what needs to be done it has to auto reset itself, I've spent a while browsing the interwebs for some help but can't seem to find anyone else asking this question. The code I attempted to use to restart was probably terribly off:
os.execl(sys.executable, sys.executable, * sys.argv)
any help is appreciated.
import os
PassCount = 0
SetUp = 0
newpath = r"PassEncryptPY"
if not os.path.exists(newpath):
os.makedirs(newpath)
f = open("PassEncryptPY/PassEncryptPY_PTF.txt", "a")
g = open("PassEncryptPY/PassEncryptPY_ETF.txt", "a")
if os.path.getsize(r"PassEncryptPY/PassEncryptPY_PTF.txt") == 0:
print("we have detected that you dont have a password")
pas = input("Your password: ")
f.write(pas)
SetUp = SetUp + 1
if os.path.getsize(r"PassEncryptPY/PassEncryptPY_ETF.txt") == 0:
print("we have detected that you dont have a email")
ema = input("Your email: ")
g.write(ema)
SetUp = SetUp + 1
if SetUp != 0:
print("Set Up complete, restarting")
f.flush()
g.flush()
os.fsync(f.fileno())
os.fsync(g.fileno())
import sys
os.execl(sys.executable, sys.executable, * sys.argv)
f.close()
g.close()
sys.argv[0]might not be enough to run it. Any chance that's your problem? If you don't know, try printing out__FILE__,sys.argv[0], andos.getcwd()right before theexecl.