get the terminal's size

Schachner, Joseph Joseph.Schachner at Teledyne.com
Mon Jan 14 12:35:37 EST 2019


I just tested the fix I proposed, in Python 2.7.13

Code:
from win32api import GetSystemMetrics

def main():
    print "Width =", GetSystemMetrics(0)
    print "Height =", GetSystemMetrics(1)

if __name__ == '__main__':
    main()

Result:
Width = 1536
Height = 864

-----Original Message-----
From: Alex Ternaute <alex at lussinan.invalid> 
Sent: Monday, January 14, 2019 6:58 AM
To: python-list at python.org
Subject: get the terminal's size

Hi there,

I want to know the number of columns of the terminal where python2 writes it's outputs.

In a terminal, I type
$ echo $COLUMNS
100

But in Python, os.getenv("COLUMNS") gets nothing.
It gets nothing as well if I try to read the output of "echo $COLUMNS" 
from a subprocess.

I feel that I'm missing something but what ?

Looking on the internet for a hint, I see that python3 has an os.get_terminal_size(). 
Please, is there something similar for python2 ?

Cheers
--
Alex



More information about the Python-list mailing list