os.path.isfile () takes the file path (string), not the file descriptor (number), so your solution will not work as you would expect.
Instead of os.isatty (), you can use
if os.isatty(1): print "text"
os.isatty()
will return True
if its argument is an open file descriptor connected to the terminal.
(Interim note that stdout
is a file descriptor 1
stderr
is a file descriptor 2
).
source share