Redirecting text output from Python functions