Understanding stdin, stdout, stderr in Python
HTML-код
- Опубликовано: 11 сен 2024
- Today we learn about the standard streams stdin, stdout and stderr as well as how to use them in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine...
💻 The Algorithm Bible Book: www.neuralnine...
👕 Programming Merch: www.neuralnine...
💼 Services 💼
💻 Freelancing & Tutoring: www.neuralnine...
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine...
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/Neu...
🎙 Discord: / discord
250K Subs - congratulations - this has always been a great channel - always informative and interesting. All the best 🤗
A lot of information, very good to watch after some previous videos about theory if in out and error streams in any OS.
0:00 I'm wondering if I need this, let's see.
Useful video :) I learned something today :)
11:00 print has a flush parameter and I can avoid the printing the new line on print function calls.
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.
Really useful
very helpful! thank you
Good job ❤
I wonder if that works with logging....
Thanks 😊
thanks
echo 'i learned' | python3 -c "print(sys.stdin.read(),end='this')"
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
Thanks 🤍
Thx_.
information , ℹ️
Zoom your video blurry