Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the path of the current TTY in Python

How do you get the device path for the current TTY?

Python has sys.stdin, sys.stdout and os.ttyname but you cannot pass either of the formers to the latter because it requires a file descriptor.

like image 268
Bruno Bronosky Avatar asked Apr 20 '15 20:04

Bruno Bronosky


1 Answers

You can pass sys.stdout.fileno to os.ttyname:

In [3]: os.ttyname(sys.stdout.fileno())
Out[3]: '/dev/pts/24'
like image 144
Padraic Cunningham Avatar answered Sep 28 '22 11:09

Padraic Cunningham