Python File isatty() 方法

Python File(檔) 方法 Python File(檔) 方法


概述

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

語法

isatty() 方法語法如下:

fileObject.isatty();

參數

返回值

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

實例

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

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

# 打開檔

fo = open("zaixian.txt", "wb")
print "檔案名為: ", fo.name

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

# 關閉檔

fo.close()

以上實例輸出結果為:

檔案名為:  zaixian.txt
返回值 :  False

Python File(檔) 方法 Python File(檔) 方法