Skip to content

Instantly share code, notes, and snippets.

@fhssn1
Created March 20, 2014 19:44
Show Gist options
  • Save fhssn1/9672238 to your computer and use it in GitHub Desktop.
Save fhssn1/9672238 to your computer and use it in GitHub Desktop.
Capture output (print or stdout) of a library function (or some command that you don't want to mess with) to a file
import sys
stdout = sys.stdout
with open('outfile.log','w') as sys.stdout:
library_function_that_prints()
sys.stdout = stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment