Python | shutil.get_terminal_size() method
Last Updated :
10 Jan, 2020
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories.
shutil.get_terminal_size()
method tells the size of the terminal window. As terminal is of the two dimensions, so the environment variables COLUMNS and LINES respectively is checked. If the variable is defined and the value is a positive integer then it is used. When COLUMNS or LINES is not defined then the terminal connected to sys.__stdout__ is queried by invoking os.get_terminal_size().
Syntax: shutil.get_terminal_size(fallback=(columns, lines))
Parameters:
fallback: A tuple representing the columns and lines of terminal. The default value of fallback used by many terminal emulators is (80, 24).
Return Value: This method returns a named tuple of type os.terminal_size.
Example #1 :
import shutil
terminal_size = shutil.get_terminal_size()
print (terminal_size)
|
Output:
os.terminal_size(columns=80, lines=24)
Example #2 :
import shutil
terminal_size = shutil.get_terminal_size(( 40 , 20 ))
print (terminal_size)
|
Output:
os.terminal_size(columns=40, lines=20)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...