0

I'd like to print some errors in red and then go back to the standard color of the terminal. I'm doing this using the same bash commands e.g. \033[1;31;40m

In python it would be:

print ('\033[1;31;40mERROR:\033[1;37;40m') 

the problem is that this works for my own terminal but if someone would have some different coloring the exit coloring wouldn't be the same

So I was wondering if there's a way in python to know what is the value of PS1 in bash or maybe some approach even more general to go back to the original coloring

p. l.
  • 55
  • 4
  • These are interpreted by the terminal, not `bash`. How can you know which terminal I'm using? FWIW, all the terminals I've used in GNU/Linux has support for the ANSI escape sequences. – heemayl Jul 17 '19 at 10:08
  • Look for environment variables like `TERM`, `COLORTERM`. – anishsane Jul 17 '19 at 10:10
  • Probably a better solution to use a colored logger module. For example: https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output – milanbalazs Jul 17 '19 at 10:21

1 Answers1

0

Using 0m will reset the color. print (Something \033[0m)

Reference: here

j23
  • 3,139
  • 1
  • 6
  • 13