PW Akshay

Generation

generate functionTue, 03 Jan 2023

centralize the printed output in python using shutil

import shutil def print_centralized(string, symbol=1): """ print a string to the center of the terminal :param string: The string to print :param symbol: The width of the symbol (1 or 2) :return: None """ term_size = shutil.get_terminal_size() break_line = (term_size.columns - len(string)) // 2 if symbol == 1: begin = "| " + "-" * break_line end = "-" * break_line + " |" else: begin = "|-" + "-" * break_line end = "-" * break_line + "-|" print(begin + string + end)

Questions about programming?Chat with your personal AI assistant