How to print a multiline string centralised (Python)

Question:

I’m trying to print the following string in a centralised position in the console, but .center() doesn’t seem to work

"""             ,      ,
             (.-""-.)
        |  /      /  /|
        |  / =.  .=  / |
        (    o/o   / )/
         _, '-/  -' ,_/
           v   __/   v
            __/__/ /
         ___ |--|/ /___
       /`          /    `
"""
Asked By: AlexiBoxi

||

Answers:

The problem is that in your input string you have spaces before your pixel art.
I used also the answer provided in the comments (link).

import shutil

SIZE = shutil.get_terminal_size()
COLUMNS = SIZE.columns


def tty_center_str(s: str):
    print(s.center(COLUMNS))


def tty_center_multiline(s: str):
    for line in s.splitlines():
        tty_center_str(line.strip())

Output:

>>> tty_center_multiline(s)
                                    ,      ,                                    
                                    (.-""-.)                                    
                               |  /      /  /|                               
                               |  / =.  .=  / |                               
                               (    o/o   / )/                               
                                _, '-/  -' ,_/                                
                                  v   __/   v                                  
                                   __/__/ /                                  
                                ___ |--|/ /___                                
                              /`          /    `                               

Answered By: crissal
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.