什么是termios.TIOCGWINSZ

Wil*_*iam 11 python

我想得到终端的大小.我正在使用此功能:

import sys, struct, fcntl, termios

s = struct.pack('HHHH', 0, 0, 0, 0)
t = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
print(struct.unpack('HHHH', t))
Run Code Online (Sandbox Code Playgroud)

但到底是termios.TIOCGWINSZ什么?

glg*_*lgl 17

这是一个神奇的常数,由你运行的系统决定.由终端司机.

结合使用ioctl(),它可以在您的情况下调用IOCtl来获取窗口大小.因此,名称TIOCGWINSZ,IOCtl to Get the WINdow Si Ze.

这些文档可能会帮助您清理.