+ 7

How can i put formated text in python? (bold, italic, etc.)

formated text in python? (bold, italic, etc.)

25th Jun 2020, 8:00 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
7 odpowiedzi
+ 3
Tricker red = '\033[91m' green = '\033[92m' blue = '\033[94m' bold = '\033[1m' italics = '\033[3m' underline = '\033[4m' end = '\033[0m' print (red + underline + 'Test!... Test!' + end) something like this?
25th Jun 2020, 8:59 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
+ 3
A little more pythonic Module: https://gist.github.com/dnmellen/5584007 import colors with colors.pretty_output(colors.BOLD, colors.FG_GREEN) as out: out.write("This is a bold green text") with colors.pretty_output(colors.BG_BLUE) as out: out.write("This output have a blue background but you " + colors.BOLD + colors.FG_RED + "can" + colors.END + " mix styles")
25th Jun 2020, 8:45 AM
Ruben Gasparyan
Ruben Gasparyan - avatar
+ 2
Thanks for the help Ruben Gasparyan
25th Jun 2020, 8:46 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
+ 1
You are welcome!
25th Jun 2020, 8:49 AM
Ruben Gasparyan
Ruben Gasparyan - avatar
0
Hi, for example from terminal import render print render('%(BG_YELLOW)s%(RED)s%(BOLD)sHey this is a test%(NORMAL)s') print render('%(BG_GREEN)s%(RED)s%(UNDERLINE)sAnother test%(NORMAL)s') you can change background color, color and formated text
25th Jun 2020, 8:40 AM
Ruben Gasparyan
Ruben Gasparyan - avatar
0
You can also do it by using custom gui shell or ANSI escape characters. For Bold it's , "\033[3m" E.g. print('\003[3m' + 'Your text here' + '\033[0m') Always end your string with '\033[0m' There are many more formats available, use wiki for that. However, Sololearn shell doesn't support ANSI chars, therefore it is not possible here.
25th Jun 2020, 8:55 AM
Tricker
0
Ayush Dwivedi 🇮🇳 yes. You can also use semi colon for multi formatting.
25th Jun 2020, 9:01 AM
Tricker