Colours in Python

nypon

New Member
Joined
Jul 7, 2026
Messages
2
Reaction score
0
Credits
22
So when I run Python in the terminal and type some code in, it's all white. No colours no matter what type of command/whatever I type. I read that I could maybe install something called 'blessings' by typing 'pip install blessings', and then use it in a script by typing 'from blessings import Terminal'. I wanted to double check whether that's the best way to do things, and safe etc? Appreciate any feedback.
 


There are a number of ways to get coloured text in python.
The easiest is just to use ANSI escape codes, which are built in terminal codes that will change the colour when they are printed to the screen.
I don't have time to create any examples right now, but a quick bit of duckduckgo-fu yielded this tutorial, which gives you a few different options:
 
There are a number of ways to get coloured text in python.
The easiest is just to use ANSI escape codes, which are built in terminal codes that will change the colour when they are printed to the screen.
I don't have time to create any examples right now, but a quick bit of duckduckgo-fu yielded this tutorial, which gives you a few different options:
Hi! Thanks for your reply. I'm a bit confused by the above tutorial though, as it seems like it's for manually formatting text with different colours if I understand correctly. What I'd like is just to have the standard Python colours corresponding with certain key words (like 'print' being green), not to write a text string with a certain colour, for example. Not for style, but for clarity. Is there any way to do that?
 


Follow Linux.org

Staff online

Members online


Latest posts

Top