Latest web development tutorials

Python3 File isatty() 方法

Python3 File(文件) 方法 Python3 File(文件)方法


概述

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

語法

isatty() 方法語法如下:

fileObject.isatty(); 

參數

返回值

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

實例

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

#!/usr/bin/python3

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

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

# 关闭文件
fo.close()

以上實例輸出結果為:

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

Python3 File(文件) 方法 Python3 File(文件)方法