How to get terminal width?

Doug Stanfield DOUGS at oceanic.com
Wed May 3 15:07:03 EDT 2000


[cpmcda01 at shark.kitenet.net wrote:]
> 
> | I need to write a command line script in Python that needs 
> to  know the width
> | of the terminal in characters. I've looked through several 
> modules and
> | haven't yet found what I'm looking for. Does anyone know 
> where I need to
> | look?


[and Donn Cave replied:]
> Contrary to popular belief, the COLUMNS environment variable isn't
> universally available on UNIX platforms.  The last time I saw it was
> on an obscure platform based on System V 3.2, and you don't get it
> on contemporary Berkeley or Linux platforms, ...

COLUMNS is there on my just installed Mandrake 7, a new Storm install, a Red
Hat 5.2, 6.1, and a Mandrake 6.x.  In my world thats almost universal,
although the sometimes accessed Solaris system doesn't have it.

Also, if you use curses there is a stdscr.getmaxyx() function.

-Doug-




More information about the Python-list mailing list