Python os.isatty() Method

Python File(文件) 方法Python 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. If yes, it returns true; otherwise, it returns False.

Syntax

isatty()The method syntax is as follows:

os.isatty()

Parameters

  • None

Return Value

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

Example

The following example demonstrates the use of the isatty() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

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

# 写入字符串
os.write(fd, "This is test")

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

print "返回值: ", ret

# 关闭文件
os.close( fd )

The output of executing the above program is:

返回值:  False

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions