Is shutil.get_terminal_size useless?

Grant Edwards grant.b.edwards at
Sat Jan 28 11:01:03 EST 2017

On 2017-01-28, Steve D'Aprano <steve+python at> wrote:

> Right: I want to know what the terminal window is sized to.

What do you mean by "the terminal"?

Do you mean the device to which the program's output is connected?
Since output is what you have control over, and what's width you might
want to change, that's what makes sense to me.

Or do you mean the device to which the program's input is connected?

Or do you mean the controlling tty for the process group in which the
program is running?

> The terminal size doesn't change just because I'm piping output to
> another process. Using the terminal size as a proxy for "being
> piped" is sheer insanity.

Why do you want to know what the terminal width is if it isn't to
control the format of the output?  That's why _I_ would want to know
the terminal width.  And in that case, the width of there stdout is
going is what makes the most sense to me.

> But I'm only asking one question: what's the terminal size?

The library call you're making defines "the terminal" as the device to
which stdout is connected.  You apparently which to define "the
terminal" differently.  In which case you need to use a different
library call.


More information about the Python-list mailing list