0

I am currently making a minesweeper bot and when it detects that a game is done I would like it to restart the script and reset all the variables so it can restart completely the same as if I were to ctrl c then restart except inside of the script. (on a mac)

TLDR: completely restart script mid script

Example:

    def restart(self):
        if locateOnScreen('images/finish/gamefinish.png', grayscale = True) != None:
            click('images/finish/gamefinish.png')
            **CODE TO RESTART HERE**
        else:
            pass
Riceblades
  • 319
  • 1
  • 17

1 Answers1

0

The answer to this is

os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)

credit: @SangminKim (and @DavidCamp for suggesting) https://stackoverflow.com/a/48130152/19079252

Riceblades
  • 319
  • 1
  • 17