Python os.isatty() Method
Example
Checks whether a file is open and connected to terminal or not:
#Import os Library
import os
# Open a file
fd = os.open( "test.txt",
os.O_RDWR|os.O_CREAT )
# Write one string
os.write(fd, "This is a
test")
# Check file with isatty()
ret = os.isatty(fd)
print
("Returned value is: ", ret)
# Close opened file
os.close(fd)
Definition and Usage
The os.isatty()
method returns whether a file descriptor is open and connected to a tty(-like) device
or not.
tty(-like) device means a device that acts like a teletype, for example a terminal.
A file descriptor is a string value of a file or input/output resource. It performs I/O operations like read, write, send, etc.
Note: Available only on UNIX platforms.
Syntax
os.isatty(fd)
Parameter Values
Parameter | Description |
---|---|
fd | Required. Specifies a file descriptor to be checked |
Technical Details
Return Value: | An bool value. Returns TRUE if the file descriptor is open and connected to tty(-like) device,
FALSE otherwise
|
---|---|
Python Version: | pre-2.7 |