Python os.get_terminal_size()
Python中的os.get_terminal_size()方法用于查询终端的大小。此方法以columns和行对的形式返回终端的大小。这里,columns用字符表示终端窗口的宽度,行用字符表示终端窗口的高度。
语法:os.get_terminal_size(fd = STDOUT_FILENO)
参数:
fd(可选):文件描述符。它指定应该查询哪个文件描述符。fd参数的默认值为STDOUT_FILENO或标准输出。
返回类型:此方法返回类’os.terminal_size ‘的对象,该对象包含columns和行属性。
示例1
使用os.get_terminal_size()方法
# Python program to explain os.get_terminal_size() method # importing os module import os # Get the size # of the terminal size = os.get_terminal_size() # Print the size # of the terminal print(size)
输出:
os.terminal_size(columns=80, lines=24)
版权声明:本页面内容旨在传播知识,为用户自行发布,若有侵权等问题请及时与本网联系,我们将第一时间处理。E-mail:284563525@qq.com