print_and_capture function

Capture the output of printing an object