A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/python/os_ttyname.htm below:

Python os.ttyname() Method

Python os.ttyname() Method

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.

Syntax

Following is the syntax for Python os.ttyname() method −

os.ttyname(fd)
Parameters

The Python os.ttyname() accepts only one parameter −

Return Value

The Python os.ttyname() method returns a string which specifies the terminal device.

Example

In 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