获取Linux控制台列数(字符数)行数

      找对方法就比较简单了,直接上代码(适用Linux)。

import fcntl
import sys
import termios
import struct


def get_terminal_size():
    """
    获取Linux控制台窗口尺寸
    :return: (行数,列数)
    """
    t = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, "1234")
    return struct.unpack('HH', t)

      直接调用函数可获得返回值:print(get_terminal_size())

  

猜你喜欢

转载自blog.csdn.net/tww124849980/article/details/127510375
今日推荐