Latest web development tutorials

Python3 os.isatty () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.isatty () method is used to determine if the file descriptor fd is open, and is connected tty (-like) device, it returns true, otherwise False.

grammar

isatty () method syntax is as follows:

os.isatty()

parameter

  • no

return value

If the file descriptor fd is open, and connected with the tty (-like) device, it returns true, otherwise False.

Examples

The following example demonstrates isatty () method of use:

#!/usr/bin/python3

import os, sys

# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# 写入字符串
str = "This is w3big.com site"
os.write(fd,bytes(str, 'UTF-8'))

# 使用 isatty() 查看文件
ret = os.isatty(fd)

print ("返回值: ", ret)

# 关闭文件
os.close( fd )

The above program output is:

返回值:  False

Python3 OS file / directory methods Python3 OS file / directory methods