Thursday, December 26, 2024
Google search engine
HomeLanguagesPython | shutil.get_terminal_size() method

Python | shutil.get_terminal_size() method

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 :




# 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) 


Output:

os.terminal_size(columns=80, lines=24)

Example #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) 


Output:

os.terminal_size(columns=40, lines=20)
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments