How to print a message box in python?
python string
I'm trying to print out a message within a created box in python, but instead of it printing straight down, it prints horizontally.
When you use list comprehension you get the output as list , as seen by your output, to see the new line character you need to print the result
And also you are using columns to multiply - which is only one for all strings. Change it to `row'
def border_msg(msg): row = len(msg) h = ''.join(['+'] + ['-' *row] + ['+']) result= h + '\n'"|"+msg+"|"'\n' + h print(result)
The above answers are good if you only want to print one line, however, they break down for multiple lines. If you want to print multiple lines you can use the following:
This will print a box around a multi-line string that is left-aligned with the specified padding values determining the positioning of the text in the box. Adjust accordingly.
If you would like to center the text, just use one padding value and interleave half of the spaces value from the spaces = h_len - len(m) line between the pipes.
Here's a mildly elaborated function for printing a message-box with optional title and indent which centers around the longest line:
"
#programmingknowledge #codewithharry #coder #pandas #trending #flask #Django #mail #bottel #begginers #jinja #dynamicprograming #specialcode
In questa pagina del sito puoi guardare il video online Box input text in Python || Python for begginers || basic code in python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Sachin Meena 31 gennaio 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 102 volte e gli è piaciuto 5 spettatori. Buona visione!