-
-
Save DahlitzFlorian/1568c32797067ec0a41dcbf2418fd61a to your computer and use it in GitHub Desktop.
Provide the full working example for a user asking a question on the video "How to Capture What Is Written to stdout in Python"
This file contains 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 contextlib | |
import io | |
captured_output = io.StringIO() | |
with contextlib.redirect_stdout(captured_output): | |
help(pow) | |
captured_string = captured_output.getvalue() | |
print(captured_string.upper()) | |
# Output from the terminal: | |
""" | |
$ python t.py | |
HELP ON BUILT-IN FUNCTION POW IN MODULE BUILTINS: | |
POW(X, Y, Z=NONE, /) | |
EQUIVALENT TO X**Y (WITH TWO ARGUMENTS) OR X**Y % Z (WITH THREE ARGUMENTS) | |
SOME TYPES, SUCH AS INTS, ARE ABLE TO USE A MORE EFFICIENT ALGORITHM WHEN | |
INVOKED USING THE THREE ARGUMENT FORM. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment