The Python os.ttyname() method is used to return a string that represents the terminal device associated with the file descriptor passed to it. In case, the file descriptor is not associated with a terminal device, this method will raise an exception.
SyntaxFollowing is the syntax for Python os.ttyname() method −
os.ttyname(fd)Parameters
The Python os.ttyname() accepts only one parameter −
fd − This parameter specifies the file descriptor.
The Python os.ttyname() method returns a string which specifies the terminal device.
ExampleIn the following example, we are checking the terminal device associated with the given file descriptor using os.ttyname() method.
import os, sys # Showing current directory print ("Current working dir :%s" %os.getcwd()) # Changing dir to /dev/tty fd = os.open("/dev/tty",os.O_RDONLY) p = os.ttyname(fd) print ("the terminal device associated is: ") print (p) print ("done!!") os.close(fd) print ("file closed successfully!!")
When we run above program, it produces following result −
Current working dir :/home/tp/Python the terminal device associated is: /dev/tty done!! file closed successfully!!
python_files_io.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4