Python3 os.isatty() Method
Python3 OS File/Directory Methods
Overview
The os.isatty() method is used to determine whether the file descriptor fd is open and connected to a tty(-like) device, returning true if so, otherwise False.
Syntax
isatty()The method syntax is as follows:
os.isatty()
Parameters
- None
Return Value
Returns true if the file descriptor fd is open and connected to a tty(-like) device, otherwise False.
Example
The following example demonstrates the use of the isatty() method:
#!/usr/bin/python3
import os, sys
# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# 写入字符串
str = "This is example.com site"
os.write(fd,bytes(str, 'UTF-8'))
# 使用 isatty() 查看文件
ret = os.isatty(fd)
print ("返回值: ", ret)
# 关闭文件
os.close( fd )
Executing the above program produces the following output:
返回值: FalseOther Extensions