get the terminal's size

Thomas Jollans tjol at tjol.eu
Mon Jan 14 08:27:13 EST 2019


On 14/01/2019 12.57, Alex Ternaute wrote:
> 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(). 

Use that then.

> Please, is there something similar for python2 ?

I suspect there is some solution in the curses module...




More information about the Python-list mailing list