Python pty Module
Note: The pty
module is Unix-only.
Example
Get a master/slave pty pair (Unix only):
import pty, os
m, s = pty.openpty()
print(os.ttyname(s))
Try it Yourself »
Definition and Usage
The pty module manages pseudo-terminals (ptys).
Use it to create pty pairs or spawn programs that expect a terminal (testing or automation).
Members
Member | Description |
---|---|
fork() | Fork a child process using a new pseudo-terminal as controlling tty. |
openpty() | Open a new pty and return master/slave file descriptors. |
spawn() | Spawn a process and connect its stdio to the current terminal. |