Created
March 20, 2014 19:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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