Python File isatty() Method

Python File(文件) 方法Python File Methods


Overview

isatty()The method detects whether the file is connected to a terminal device. Returns True if so, otherwise False.

Syntax

The syntax for the isatty() method is as follows:

fileObject.isatty(); 

Parameters

  • None

Return Value

Returns True if connected to a terminal device, otherwise False.

Examples

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

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

# 打开文件
fo = open("example.txt", "wb")
print "文件名为: ", fo.name

ret = fo.isatty()
print "返回值 : ", ret

# 关闭文件
fo.close()

The output of the above example is:

文件名为:  example.txt
返回值 :  False

Python File(文件) 方法Python File Methods

Other Extensions