Latest web development tutorials

Python3 os.openpty () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.openpty () method is used to open a new pseudo-terminal pair. Back pty and tty file descriptor.

grammar

openpty () method syntax is as follows:

os.openpty()

parameter

  • no

return value

Returns the file descriptor pair, master and slave.

Examples

The following example demonstrates openpty () method of use:

#!/usr/bin/python3

import os

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

print (m)
print (s)

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

The above program output is:

3
4
3
/dev/pty0

Python3 OS file / directory methods Python3 OS file / directory methods