Python - File isatty() Method


Advertisements

The Python file isatty() method is used to check whether the file is connected or associated with a terminal device or not. It returns true if it is connected or associated with a terminal device, else returns false.

Syntax


file.isatty()

Parameters

No parameter is required.

Example

In the below example, Python file isatty() method is used to check whether the file called MyFile is connected or associated with a terminal device or not. It returns false in this case as it is not connected with any terminal device.

MyFile = open("python_test.txt", "r")

print("Name of the file:", MyFile.name)
print("isatty() return value:", MyFile.isatty())

Output

Name of the file: python_test.txt
isatty() return value: False

Python File Handling Methods
Advertisements