Easy Tutorial
❮ Python Set Python Json ❯

Python3 os.isatty() Method

Python3 OS File/Directory Methods


Overview

The os.isatty() method is used to determine if the file descriptor fd is open and connected to a tty(-like) device. It returns True if so, otherwise False.

Syntax

The syntax for the isatty() method is as follows:

os.isatty()

Parameters

Return Value

Returns True if the file descriptor fd is open and connected to a tty(-like) device, otherwise False.

Example

The following example demonstrates the use of the isatty() method:

#!/usr/bin/python3

import os, sys

# Open a file
fd = os.open("foo.txt", os.O_RDWR|os.O_CREAT)

# Write a string
str = "This is tutorialpro.org site"
os.write(fd, bytes(str, 'UTF-8'))

# Check if the file is a tty
ret = os.isatty(fd)

print("Return value: ", ret)

# Close the file
os.close(fd)

Executing the above program outputs:

Return value:  False

Python3 OS File/Directory Methods

❮ Python Set Python Json ❯