python - print: "IOError: [Errno 9] Bad file descriptor" -
i understand why getting "bad file descriptor" error when printing no console post: why getting ioerror: (9, 'bad file descriptor') error while making print statements?.
my question is, how can detect if stdout available? can this:
if os.path.isfile(2): print "text" thanks
os.path.isfile() takes file path (a string), not file descriptor (a number), solution not work expect.
you can use os.isatty() instead:
if os.isatty(1): print "text" os.isatty() return true if argument open file descriptor connected terminal.
(in passing, note stdout file descriptor 1. stderr file descriptor 2).
Comments
Post a Comment