本文實例講述了Python實現的重啟關機程序的方法,對Python程序設計有一定的參考價值。具體方法如下:
實例代碼如下:
#!/usr/bin/python #coding=utf-8 import time from os import system runing = True while 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 = True print '程序結束~~~!'
該實例在linux下測試通過,windows的話需要判斷執行命令。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
