You are here : python_2ososisatty

os.isatty() - os


The method isatty()returns True if the file descriptor fd is open and connected to a tty(-like) device, else False.

  • fd -- This is the file descriptor for which association needs to be checked.


os.isatty( fd )



import os, sys

# Open a file
fd = "foo.txt", os.O_RDWR|os.O_CREAT )

# Write one string
os.write(fd, "This is test")

# Now use isatty() to check the file.
ret = os.isatty(fd)

print "Returned value is: ", ret

# Close opened file
os.close( fd )

Output / Return Value

When we run above program, it produces following result:

Returned value is: False


Alternatives / See Also