The method ttyname() returns a string, which specifies the terminal device associated with fd. If fd is not associated with a terminal device, an exception is raised.
Following is the syntax for ttyname() method ?
This method returns a string which specifies the terminal device.
The following example shows the usage of 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 "Closed the file successfully!!"
When we run above program, it produces following result ?
Current working dir is :/tmp
the terminal device associated is:
Closed the file successfully!!