Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to run a program at a fixed time every day

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use python to run a program regularly every day". In daily operation, I believe many people have doubts about how to use python to run a program regularly every day. Xiaobian consulted all kinds of materials and sorted out simple and easy to use operation methods. I hope to answer your doubts about "how to use python to run a program regularly every day"! Next, please follow the small series to learn together!

Idea: Use the time function to return the time string and the specified time string to compare, when equal, perform the corresponding operation. I don't know what everyone's thinking is, I feel like this is more CPU consuming...

Set this to 15:30:10 to output the corresponding content, and modify what needs to be performed.

import timewhile True: time_now = time.strftime("%H:%M:%S", time.localtime()) #Refresh if time_now == "15:30:10": #Set the time of day here #Replace line 3 with action to be performed print("hello") subject = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + "timed send test" print(subject) time.sleep(2) #Because it is timed in seconds, pause for 2 seconds so that it does not execute multiple times in 1 second

The code for the test was changed to the following, and the action was executed when the number of seconds in each time was "10." Use this code to test the action of sending an email before, no problem, received the email.

import timewhile True: time_now = time.strftime("%S", time.localtime()) #Refresh if time_now == "10": #Set the time of day here #Replace line 3 with action to be performed print("hello") subject = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + "timed send test" print(subject) time.sleep(2) #Because it is timed in seconds, it is suspended for 2 seconds, so that it will not be executed many times in 1 second. The study of "how to use python to run a certain program every day" is over. I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report