Python 3 教程 Python3 File isatty() 方法

valentino · 2022-03-14 20:38:32 · 热度: 10

概述

isatty() 方法检测文件是否连接到一个终端设备,如果是返回 True,否则返回 False。

语法

isatty() 方法语法如下:

fileObject.isatty();

参数

返回值

如果连接到一个终端设备返回 True,否则返回 False。

实例

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

#!/usr/bin/python3

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

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

# 关闭文件
fo.close()

以上实例输出结果为:

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

查看更多 Python File(文件) 函数

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册