I am trying to code a Class, which upon calling, for example: print(TimeNow.time_now)
would print current time (but it's not realtime), as in, each time I call it, it doesn't return updated value.
If I tried this every time, it would make my code long, so I am trying to code it in a Class so that I can easily call it wherever I want to print time:
time_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(time_now)
Full code:
import datetime
command = ""
class TimeNow:
time_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
while command != "quit":
command = input("-> ").lower()
if command == "1":
print(TimeNow.time_now)