def read_stdin ( ) : if sys . stdin . isatty ( ) and sys . stdout . isatty ( ) : print ( '\nReading from stdin until end of file (Ctrl + D)...' ) return sys . stdin . read ( )
python stdin file or tty
Read text from stdin and print a helpful message for ttys .
def read_stdin():
    """ Read text from stdin, and print a helpful message for ttys. """
    if sys.stdin.isatty() and sys.stdout.isatty():
        print('\nReading from stdin until end of file (Ctrl + D)...')

    return sys.stdin.read()