Python 작은 스크립트: 정기적으로 물 마시기 알림

高洛峰
풀어 주다: 2017-02-16 11:19:47
원래의
2645명이 탐색했습니다.

#
# -*- coding: utf-8 -*-  
import subprocess
import time,os

def createFile(filename):
    if os.path.exists(filename) == False:
        open(filename, "a").close()
    if os.path.getsize(filename):
        pass
    else:
        f = open(filename, "a")
        f.write("多喝水!!")
        f.close()
        
def getThisHours():
    timeInfo = time.localtime()
    return timeInfo[3]

def printTips(filename):
    createFile(filename);
    sub2 = subprocess.Popen(['notepad', filename]);

lastHours = getThisHours()

try:
    fileName = "Tips.txt"
    while True:
        nowHours = getThisHours()
        if(nowHours > lastHours):
            lastHours = nowHours
            printTips(fileName)
        time.sleep(660);#11分钟循环一次
except Exception as e:
    f = open("error.log", "a")
    f.write(str(e) + "\n")
    f.close()
로그인 후 복사
로그인 후 복사

는 계획 작업에 스크립트를 추가하지 않고도 정기적으로 식수를 상기시킵니다(접미사는 .pyW로 저장되어 콘솔 창에 표시되지 않음)


🎜>

#
# -*- coding: utf-8 -*-  
import subprocess
import time,os

def createFile(filename):
    if os.path.exists(filename) == False:
        open(filename, "a").close()
    if os.path.getsize(filename):
        pass
    else:
        f = open(filename, "a")
        f.write("多喝水!!")
        f.close()
        
def getThisHours():
    timeInfo = time.localtime()
    return timeInfo[3]

def printTips(filename):
    createFile(filename);
    sub2 = subprocess.Popen(['notepad', filename]);

lastHours = getThisHours()

try:
    fileName = "Tips.txt"
    while True:
        nowHours = getThisHours()
        if(nowHours > lastHours):
            lastHours = nowHours
            printTips(fileName)
        time.sleep(660);#11分钟循环一次
except Exception as e:
    f = open("error.log", "a")
    f.write(str(e) + "\n")
    f.close()
로그인 후 복사
로그인 후 복사

정기적으로 물을 마시도록 상기시켜 주며, 예약된 작업에 스크립트를 추가할 필요가 없습니다(접미사를 . pyw 및 콘솔 창이 나타나지 않습니다)


더 많은 Python 스크립트: 정기적으로 물 마시기 알림 관련 기사를 보려면 PHP 중국어 웹사이트를 참고하세요!


관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!