Easy Tutorial
❮ Ref Set Intersection_Update Python Att Time Tzset ❯

Python3 os.ttyname() Method

Python3 OS File/Directory Methods


Overview

The os.ttyname() method returns a string that represents the terminal device associated with the file descriptor fd. If fd is not associated with a terminal device, an exception is raised.

Syntax

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

os.ttyname(fd)

Parameters

Return Value

Returns a string that represents the terminal device associated with the file descriptor fd.

Example

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

#!/usr/bin/python3

import os, sys

# Display the current directory
print ("Current directory :%s" %os.getcwd())

# Change directory to /dev/tty
fd = os.open("/dev/tty",os.O_RDONLY)

p = os.ttyname(fd)
print ("Associated terminal is: ")
print (p)
print ("done!!")

os.close(fd)
print ("File closed successfully!!")

Output of the above program is:

Current directory :/tmp
Associated terminal is:
/dev/tty
done!!
File closed successfully!!

Python3 OS File/Directory Methods

❮ Ref Set Intersection_Update Python Att Time Tzset ❯