Python Tutorial Python Advanced Python References Python Libraries

Python - File isatty() Method



The Python 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.

Return Value

Returns True if it is connected or associated with a terminal device, else returns False.

Example

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

MyFile = open("test.txt", "w")

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

The output of the above code will be:

Name of the file: test.txt
isatty() returns: False

❮ Python File Handling Methods

5