I know I can redirect stdout to a file with:
stdout = open("file", "a")
but how do I send it to a python function instead. I am working with a headless server where I would like to redirect the output to an easily monitored external source.
I would like to do:
def my_print_handler():
# do something useful with the output other than printing it to a screen nobody sees
stdout = my_print_handler()
print ("Hello World") # sent to my_print_handler rather than screen