Python os.isatty() method
Python OS file/directory methods
Overview
The os.isatty() method returns True if the file descriptor fd is open and connected to a tty(-like) device, otherwise False.
Syntax
The **isatty()** method syntax is as follows:
os.isatty()
Parameters
- None
Return Value
Return True if the file descriptor fd is open and connected to a tty(-like) device, otherwise False.
Example
The following example shows how to use the isatty() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Write string
os.write(fd, "This is test")
# Use isatty() to check file
ret = os.isatty(fd)
print "返回值: ", ret
# Close file
os.close( fd )
The output of the above program is:
返回值: False