How to Capture What Is Written to stdout in Python

preview_player
Показать описание
In this Python tutorial, you'll learn how to redirect what is written to stdout in Python.

This can be helpful when dealing with functions like the built-in help function.

First, we will have a look at the built-in help function and why it is a perfect candidate for the task at hand.

Secondly, I'll show you how to redirect everything from stdout to a text file.

Lastly, we will see how to capture what is written to stdout in a string variable, so we can do whatever we would like to do with the text.

GitHub Repository

SUBSCRIBE to become a Pythonista!

Follow me on Twitter!

Check out my website for more!

~~~~~~~~~~ OUTLINE ~~~~~~~~~~
00:00 Introduction
00:14 Built-in help function
01:21 Send stdout to a file
03:19 Send stdout to stderr
03:54 Capture stdout in a variable

#python
Рекомендации по теме
Комментарии
Автор

Dear Florian
Exactly what I need, GOD bless you😇

zohrehkarimzadeh
Автор

Thanks, Florian! This will come in handy someday, and I might not have found it for myself.

I'll go look it up, but it would be helpful to include a note here about how/whether you can turn redirection off, too.

rantalbott
Автор

Thank so much.
I was looking for this one only some times back.

dibyabehera
Автор

Great video, didn't know about this, might come in handy some time.

nielsbach-srensen
Автор

What if the output is from subprocess that runs for quiet some time and you need to capture its output real time. Like output from pyinstaller.

FufaTujuba
Автор

But when I tried to print captured_string.upper(), I couldn't. It was printing the original captured_string, like I haven't saved it to a variable. Is there a solution for that? Thanks

lukab
welcome to shbcf.ru