Steve D'Aprano <steve+pyt...@pearwood.info> writes: > On Fri, 6 Oct 2017 09:33 pm, Ben Bacarisse wrote: > >> A general solution to the (rather odd) complaint about silent waiting >> should really check any input fileno to see if a prompt is needed. You >> could argue, though, that anyone who's re-arranged a program's input so >> that some non-zero input fileno is attached to a terminal won't need the >> prompt! > > I'm afraid I don't quite know if I'm understanding you or not. > > I think you mean to say I should look at sys.stdin.fileno(), and if it is 0, > then write a prompt, and if not, just read from stdin (possibly blocking, > waiting for input). > > Is that right? > > But aren't there circumstances where fileno 0 isn't attached to a terminal, > and writing a prompt would be inappropriate?
No. The point was that other file descriptors might be associated with a terminal. I could, for example, switch the input to an interactive program that interprets command to be done on some data file so that the supposedly interactive commands come form a file and I type the data at a terminal. The second point was anyone doing this probably does not need a hint about tying something. But this detail about other inputs opened by the program aside, it seems to me that what BartC (and others who want this) needs is a beginners shell that prints a helpful text whenever it starts a program (or pipeline of programs) with stdin attached to the terminal. It's not really something that every individual program should have to tackle. -- Ben. -- https://mail.python.org/mailman/listinfo/python-list