程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python learning notes (32) -- schedule library realizes calling Xiao Ming to eat regularly every day

編輯:Python

1、 install schedule library :schedule · PyPI

2、 Code practice :

import schedule# introduce schedule library
import time# introduce time library
def eating():# Define a task to perform
print(' Your mother told you to go home for dinner ')
def AA(name):# Define a task to perform
print(name+'it is time up')
name=' Xiao Ming '
schedule.every(5).seconds.do(AA,name)# Define interval 5 Run the code every second
schedule.every(10).minutes.do(eating)# Define interval 10 Run the code every minutes
schedule.every().hour.do(eating)# Define the code to run every other hour
schedule.every().day.at("11:30").do(eating)# Defined in daily 15:30 Run code
schedule.every().monday.at("11:30").do(eating)# Defined on every Monday 15:30 Run code
while True:# Keep the program running
schedule.run_pending()# Run all the tasks that can be run
time.sleep(10)# Rest after running 10 Second, check whether there are tasks that can be run 

Running results :

 

 

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved