Python3 os.openpty() Method

Python3 OS 文件/目录方法Python3 OS File/Directory Methods


Overview

The os.openpty() method is used to open a new pseudo-terminal pair. It returns the file descriptors for pty and tty.

Syntax

openpty()The method syntax is as follows:

os.openpty()

Parameters

  • None

Return Value

Returns a pair of file descriptors, master and slave.

Example

The following example demonstrates the usage of the openpty() method:

#!/usr/bin/python3

import os

# 主 pty, 从 tty
m,s = os.openpty()

print (m)
print (s)

# 显示终端名
s = os.ttyname(s)
print (m)
print (s)

The output of the above program is:

3
4
3
/dev/pty0

Python3 OS 文件/目录方法Python3 OS File/Directory Methods

Other Extensions