Python method os.openpty() is a built-in function of OS module. It opens a pseudo-terminal pair and returns a pair of non-inheritable file descriptors for the pty and tty.
The file descriptors associated with "pty" and "tty" are called as master and slave respectively.
When a program interacts with the pty, it communicates through the master file descriptor and while interacting with tty, it uses slave file descriptor.
SyntaxFollowing is the syntax for Python os.openpty() method −
os.openpty()Parameters
The Python os.openpty() method does not accept any parameters.
Return ValueThe Python os.openpty() method returns a pair of file descriptors i.e., master and slave.
ExampleThe following example shows the usage of openpty() method where we are displaying the master file descriptor and the slave terminal name.
import os # master for pty, slave for tty m,s = os.openpty() print("File descriptors for pty:") print (m) print (s) # showing terminal name s = os.ttyname(s) print("File descriptors for tty:") print (m) print (s)
When we run above program, it produces following result −
File descriptors for pty: 3 4 File descriptors for tty: 3 /dev/pts/1
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