Understanding stdin, stdout, stderr in Python

preview_player
Показать описание
Today we learn about the standard streams stdin, stdout and stderr as well as how to use them in Python.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

💼 Services 💼

🌐 Social Media & Contact 🌐
Рекомендации по теме
Комментарии
Автор

250K Subs - congratulations - this has always been a great channel - always informative and interesting. All the best 🤗

paulthomas
Автор

11:00 print has a flush parameter and I can avoid the printing the new line on print function calls.

JorgeEscobarMX
Автор

A lot of information, very good to watch after some previous videos about theory if in out and error streams in any OS.

МихаилФедосеев-еб
Автор

I like to include a function function for printing to stderr so I don't need to keep typing the "file=":
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)

Most of the time when you're reading from stdin, you'll want to process one line at a time. If you don't need a context manager for some other reason, you can just treat sys.stdin as an iterable:
for line in sys.stdin:
if len(line) == 0:
# End of file. Do final stuff here
sys.exit(0)
line = line.rstrip()

Notice the rstrip(): reading includes the terminating (CR and) LF, and you usually don't want them as part of the data.

rantalbott
Автор

0:00 I'm wondering if I need this, let's see.

JorgeEscobarMX
Автор

Useful video :) I learned something today :)

elenakusevska
Автор

I wonder if that works with logging....

richardboreiko
Автор

echo 'i learned' | python3 -c "print(sys.stdin.read(), end='this')"

ChristopherBruns-oo
Автор

POPos is no longer my fav distro. nvim is still running on version 6.1.
You should try a WM in Arch. May be Hyprland or sway

Little-bird-told-me