#!/usr/bin/env python3

from datetime import datetime

#our timestamping function, accurate to milliseconds
#(remove [:-3] to display microseconds)
def get_time():
    return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]

def rd_print(log, *args, **kwargs):
    print(get_time(), *args, **kwargs)
    if log:
        print(get_time(), *args, **kwargs, file=log, flush=True)

#!/usr/bin/env python3

from datetime import datetime

#our timestamping function, accurate to milliseconds
#(remove [:-3] to display microseconds)
def get_time():
    return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]

def rd_print(log, *args, **kwargs):
    print(get_time(), *args, **kwargs)
    if log:
        print(file=log, flush=True, get_time(), *args, **kwargs)

Make rd_print() compatibile with Python 3.4.
Make rd_print() compatibile with Python 3.4.
