Python3 File isatty() Method
Overview
isatty()The method detects whether the file is connected to a terminal device. If yes, it returns True; otherwise, it returns False.
Syntax
The syntax of the isatty() method is as follows:
fileObject.isatty();
Parameters
None
Return Value
Returns True if connected to a terminal device, otherwise returns False.
Example
The following example demonstrates the use of the isatty() method:
#!/usr/bin/python3
# 打开文件
fo = open("example.txt", "wb")
print ("文件名为: ", fo.name)
ret = fo.isatty()
print ("返回值 : ", ret)
# 关闭文件
fo.close()
The output of the above example is:
文件名为: example.txt 返回值 : False
Other Extensions
Python3 File Methods