Python automatically restarts the program.
This example describes how to automatically restart the program in python. Share it with you for your reference. The specific implementation method is as follows:
#! /Usr/local/bin/python #-*-coding: UTF-8 -*-#################################### ################################# python automatically restarts the program ## ######################################## ########################## import OS, time # def close (): # print "restart the program !!!! "# Print time. strftime ('% Y. % m. % d-% H. % M. % s') # time. sleep (2) #3 seconds # p = OS. popen ('2017. bat ') # while True: # line = p. readline (); # if ''= line: # break # print line # if _ name _ = '_ main _': # close () ######################################## ########################### import timeimport sysimport osdef restart_program (): python = sys.exe cutable OS .exe cl (python, python, * sys. argv) if _ name _ = "_ main _ ": Print 'start... '# answer = raw_input (" Do you want to restart this program? ") # If answer. strip () in "y Y y yes Yes YES ". split (): # restart_program () print u "3 seconds later, the program will end... ". encode ("gbk") time. sleep (3) restart_program ()
Shows the running effect:
I hope this article will help you with Python programming.