Python3 os.isatty() Method
Python3 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/python3
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Write string
str = "This is runoob.com site"
os.write(fd,bytes(str, 'UTF-8'))
# Use isatty() to check file
ret = os.isatty(fd)
print ("返回值: ", ret)
# Close file
os.close( fd )
The output of the above program is:
返回值: False