Python文件isatty()
方法如果文件连接(与终端设备关联)到tty(类似)设备则返回True
,否则为false
。
语法
以下是isatty()
方法的语法 -
fileObject.isatty()
参数
- NA
返回值
- 如果文件连接(与终端设备相关联)到tty(类似)设备,则此方法返回
true
,否则返回false
。
示例
以下示例显示了isatty()
方法的用法。
#!/usr/bin/python3
# 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
上一篇:
Python文件对象方法
下一篇:
Python os模块方法