My requirement is to have a function that works exactly like print but adds a timestamp at top. Currently I use something like:
def tprint(var):
print(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+" :: "+str(var))
Though it gives me all required output for a specific set – e.g.,
tprint("dummy"+" print")
2017-11-09 19:38:42 :: dummy print
I am not able to completely morph it for print statement. For example, tprint("hi","hello")
and tprint("a =", a, sep='0', end='')
fail.
My requirement is not to ideally make these two statements work. But to write an alternative function for print that works for all print arguments but gives an additional timestamp along with it. I am sure this may not be a straight forward solution. But do not want to miss if someone has already figured out any similar approach.