0

I want my program to print some text at given datetime, like print("Merry Christmas!") at 25 Dec 2020 00:00. Here is my code:

import datetime

dt1 = datetime.datetime(2020, 12, 25)
dt2 = datetime.datetime(2021, 1, 1)
dt3 = datetime.datetime(2021, 2, 14)
my_dict = {
    "Merry Christmas!": dt1,
    "Happy New Year!": dt2,
    "Happy Valentine's Day!": dt3
}

for text, dt in my_dict.items():
    run_func_at(print(text), dt)

is there anyway to do something like this?

prs_wjy
  • 185
  • 1
  • 12
  • Yes, see this post: [Python - Start a Function at Given Time](https://stackoverflow.com/questions/11523918/python-start-a-function-at-given-time). – costaparas Dec 23 '20 at 10:49
  • it's not working, when the time comes it give me error like this `TypeError: 'NoneType' object is not callable` – prs_wjy Dec 23 '20 at 11:08
  • Forget it, it actually works! i should write it like this `timer = threading.Timer(delay, print, (text,))` instead of this `timer = threading.Timer(delay, print(text))` – prs_wjy Dec 23 '20 at 11:16

0 Answers0