本文實例講述了Python實現的重啟關機程序的方法,對Python程序設計有一定的參考價值。具體方法如下:
實例代碼如下:
#!/usr/bin/python#coding=utf-8import timefrom os import systemruning = Truewhile runing: input = raw_input('關機(s)OR重啟(r)?(q退出)') input = input.lower() if input == 'q' or input =='quit': runing = False print '程序退出' break seconds = int(raw_input('請輸入暫停時間(單位:秒):')) time.sleep(seconds) print '暫停時間:', seconds runing = False if input == 's': print '關機ing' system('halt') elif input == 'r': print '重啟ing' system('reboot') else: print '程序錯誤重新輸入' runing = Trueprint '程序結束~~~!'
該實例在linux下測試通過,windows的話需要判斷執行命令。
新聞熱點
疑難解答