Python File isatty() 方法

Python File(文件) 方法 Python File(文件) 方法


概述

isatty() 方法檢測文件是否連接到一個終端設(shè)備,如果是返回 True,否則返回 False。

語法

isatty() 方法語法如下:

fileObject.isatty(); 

參數(shù)

返回值

如果連接到一個終端設(shè)備返回 True,否則返回 False。

實例

以下實例演示了 isatty() 方法的使用:

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

# 打開文件
fo = open("youj.txt", "wb")
print "文件名為: ", fo.name

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

# 關(guān)閉文件
fo.close()

以上實例輸出結(jié)果為:

文件名為:  youj.txt
返回值 :  False

Python File(文件) 方法 Python File(文件) 方法