无涯教程-File函数 - file.isatty()函数

66 阅读1分钟

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()

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

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

参考链接

www.learnfk.com/python/file…