[Tutor] Printing Bold Text
Peter Otten
__peter__ at web.de
Sat Feb 1 05:24:54 EST 2020
Adam Slowley wrote:
> So I’m a beginner, learning Python for the first time so this might be a
> dumb question but here goes. I’m trying to print a text in bold. For
> example:
>
> def main():
> name=input("Enter your name:")
> print("You entered for name a value of",name)
>
> I want whatever the user inputs as his/her name to be printed in Bold
It will only work with terminals that understand ANSI escape codes, but if
you can live with that limitiation you can install termcolor:
https://pypi.org/project/termcolor/
Example:
(1) installation with pip:
$ pip install termcolor
[...]
Successfully installed termcolor
Cleaning up...
(2)
$ python
[...]
>>> import termcolor
>>> termcolor.cprint("all bold", attrs=["bold"])
all bold
>>> print("this is", termcolor.colored("red", color="red"))
this is red
Though it's hard ;) to see in a text-only mail "all bold" is printed bold
and the word "red" is shown in the color red.
More information about the Tutor
mailing list