Using the schedule Library for Python
Why schedule
Itβs simple for:
- βrun every hourβ
- βrun at 09:00 dailyβ
Example
schedule_example.py
import schedule
import time
def job():
print("running")
schedule.every(10).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)schedule_example.py
import schedule
import time
def job():
print("running")
schedule.every(10).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)Notes
- this keeps a process running
- for server deployment, cron/systemd is usually better
π§ͺ Try It Yourself
Exercise 1 β List Files with os.listdir
Exercise 2 β Join Paths with os.path.join
Exercise 3 β Write and Read a File
If this helped you, consider buying me a coffee β
Buy me a coffeeWas this page helpful?
Let us know how we did
