get the terminal's size

Grant Edwards grant.b.edwards at gmail.com
Mon Jan 14 12:15:31 EST 2019


On 2019-01-14, Peter Otten <__peter__ at web.de> wrote:
> Grant Edwards wrote:
>
> os.environ["COLUMNS"]
>
>> [...] will tell you the terminal size at the time Python was started.
>
> I admit that none of my scripts is ambitious enough to try and track
> changes in terminal size.
>
> But still, Grant's post prompted me to reread the doc and source of
> shutil.get_terminal_size(), and I think I should warn you that the
> environment variables take precedence over ioctl()-based detection
> in os.get_terminal_size().

For non-interactive programs, the environment variable approach is
usually good enough.  For interactive programs you use ncurses, slang,
newt, or somesuch library, and they deal with tracking the window size
for you (mostly).

-- 
Grant Edwards               grant.b.edwards        Yow! My haircut is totally
                                  at               traditional!
                              gmail.com            




More information about the Python-list mailing list