I'm using the ANSI escape sequence for bold text;"\033[1m" in a print statement to create a bold header for my Python project. The problem is once I write a line like this: print("\033[1m"+"title"), any normal print statement I write afterword returns in bold as well. How can I make just one specified line bold instead of everything? Code:
print("\033[1m"+"Title")
print("Why is this text in bold as well?")
In fact, any code we type into this prompt will also be colored bold, as will any subsequent output! That is how Ansi colors work: once you print out the special code enabling a color, the color persists forever until someone else prints out the code for a different color, or prints out the Reset code to disable it.
We can disable it by printing the Reset code above:
print("\033[1m"+"Title"+"\033[0m")
See here
You need to end the escape sequence. Using \033[0m will reset all formatting.
print("\033[1m"+"Title"+"\033[0m")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With