Hi there!

How do I check if stdin is empty? This is how I write in the terminal to call my program:

>> cat file.txt | python script.py


I found the solution by myself.

use sys.stdin.isatty() to find out whether the script is executed as a part of pipeline or standalone.
The method should return True if stdin is connected to a terminal, and False otherwise (pipeline or file redirection).

Thanks for the information!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.