YouTip LogoYouTip

Python3 Os Ttyname

# Python3.x Python3 os.ttyname() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The `os.ttyname()` method is used to return a string representing 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 * **fd** -- file descriptor ### Return Value Returns a string representing the terminal device associated with the file descriptor `fd`. ### Example The following example demonstrates the use of the `ttyname()` method: #!/usr/bin/python3import os, sys # Display the current directoryprint ("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!!") The output of executing the above program is: Current directory :/tmp Associated terminal is:/dev/tty done!!File closed successfully!! [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os TtynamePython3 Os Stat_Float_Times β†’