最佳答案
                                        
                                                                        
                                In Python, how do you check if sys.stdin has data or not?
I found that os.isatty(0) can not only check if stdin is connected to a TTY device, but also if there is data available.
But if someone uses code such as
sys.stdin = cStringIO.StringIO("ddd")
and after that uses os.isatty(0), it still returns True.  What do I need to do to check if stdin has data?