File函数 中的 file.isatty()函数

首页 / Python2入门教程 / File函数 中的 file.isatty()函数

Python file methodisatty()如果文件连接(与终端设备关联)到tty(-like)设备,则返回True,否则返回False。

file.isatty() - 语法

fileObject.isatty();

file.isatty() - 返回值

如果文件连接(与终端设备相关联)到tty(类似)设备,则此方法返回true,否则返回false。

file.isatty() - 示例

以下示例显示isatty()方法的用法。

无涯教程网

#!/usr/bin/python

# Open a file
fo=open("foo.txt", "wb")
print "Name of the file: ", fo.name

ret=fo.isatty()
print "Return value : ", ret

# Close opend file
fo.close()

当无涯教程运行上面的程序时,它产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/python/file-isatty.html

来源:LearnFk无涯教程网

Name of the file:  foo.txt
Return value :  False

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

机器学习40讲 -〔王天一〕

分布式协议与算法实战 -〔韩健〕

Flink核心技术与实战 -〔张利兵〕

如何落地业务建模 -〔徐昊〕

PyTorch深度学习实战 -〔方远〕

商业思维案例笔记 -〔曹雄峰〕

B端产品经理入门课 -〔董小圣〕

深入拆解消息队列47讲 -〔许文强〕

结构会议力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)