get the terminal's size

Alex Ternaute alex at lussinan.invalid
Tue Jan 15 05:26:46 EST 2019


Hi Cameron,

> My cs.tty module (on PyPI) has a ttysize function:
>   https://pypi.org/project/cs.tty/
> which just parses the output of the stty command.

> If you don't want the cs.tty module, the ttysize code is just this:
> 
>     WinSize = namedtuple('WinSize', 'rows columns')
> 
>     def ttysize(fd):
>       ''' Return a (rows, columns) tuple for the specified file
>       descriptor.
> [...]

Fine, indeed ! I've installed cs.ttyy.

I just don't understand the reason why it takes "fd" as an argument.
 
I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE, 
universal_newlines=True) and it runs fine too, so the output seems not 
really related to that fd.

Btw I did not know about namedtuple, thanks for that too.

> Hope this helps.
Greatly.

Cheers,
-- 
Alex



More information about the Python-list mailing list