Shutil模块Python提供了许多对文件和文件集合进行高级操作的函数。它属于Python的标准实用程序模块。此模块有助于自动执行文件和目录的复制和删除过程。
shutil.get_terminal_size()方法告诉终端窗口的大小。由于终端是二维的,因此分别检查了环境变量COLUMNS和LINES。如果定义了变量,并且值是正整数,则将使用它。如果未定义COLUMNS或LINES,则通过调用os.get_terminal_size()来查询连接到sys .__ stdout__的终端。
用法: shutil.get_terminal_size(fallback=(columns, lines))
参数:
fallback:一个表示终端的列和行的元组。许多终端仿真器使用的故障预置的默认值为(80,24)。
返回值:此方法返回类型为os.terminal_size的命名元组。
范例1:
# Python program to explain
# shutil.get_terminal_size() method
# importing shutil module
import shutil
# Using shutil.get_terminal_size() method
terminal_size = shutil.get_terminal_size()
# Print result
print(terminal_size) 输出:
os.terminal_size(columns=80, lines=24)
范例2:
# Python program to explain
# shutil.get_terminal_size() method
# importing shutil module
import shutil
# Using shutil.get_terminal_size() method
terminal_size = shutil.get_terminal_size((40, 20))
# Print result
print(terminal_size) 输出:
os.terminal_size(columns=40, lines=20)
相关用法
- Python next()用法及代码示例
- Python os.dup()用法及代码示例
- Python set()用法及代码示例
- Python Decimal max()用法及代码示例
- Python PIL ImageOps.fit()用法及代码示例
- Python os.rmdir()用法及代码示例
- Python sympy.det()用法及代码示例
- Python Decimal min()用法及代码示例
- Python os.readlink()用法及代码示例
- Python os.writev()用法及代码示例
- Python os.readv()用法及代码示例
- Python PIL RankFilter()用法及代码示例
- Python os.rename()用法及代码示例
- Python os.sendfile()用法及代码示例
注:本文由纯净天空筛选整理自Rajnis09大神的英文原创作品 Python | shutil.get_terminal_size() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
