Python file isatty() method

Python File isatty() Method

The isatty() method returns True if the file is connected (associated with a terminal device) to a tty (or similar) device, otherwise it returns False.

Syntax

The syntax of the isatty() method is as follows −

fileObject.isatty()

Parameters

None

Return Value

Returns True if the file is connected (associated with a terminal device), otherwise it returns False.

Example

The following example shows the usage of the isatty() method:

# Open a file
fo = open("foo.txt", "wb")
print ("Name of the file: ", fo.name)
ret = fo.isatty()
print ("Return value: ", ret)

# Close the opened file
fo.close()

When we run the above program, it produces the following output.

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

Leave a Reply

Your email address will not be published. Required fields are marked *