python定时关机小程序

发布时间:2020-12-31编辑:脚本学堂
python定时关机代码,pythos time模块与sys模块实现定时关机。

代码:
 

复制代码 代码示例:

#!/usr/bin/env python
# 定时关机

import os,time,sys
o="c:windowssystem32shutdown -s"
print "Input the hours and minutes:"
h=input()
mt=input()
t=time.localtime()
y,m,d,h1,mt1=t[:5]
if(h<h1):
    print "The time has been pass"
elif(h==h1 and mt<mt1):
    print "The time has been pass"
hm=(y,m,d,h,mt)

while 1:
    t= time.localtime(time.time())
    a=t[:5]
    if(a==hm):
        print "Time is coming"
        os.system(o)
        break
    time.sleep(31)