python-3.xtermcolor

Termcolor remove color from string


In this code it makes the string 'hello' red:

from termcolor import colored
a = colored('hello', 'red')
print(a)

Is there a way to make the variable a turn into a normal string that is not colored?


Solution

  • removing the first and last 4 characters of the string should remove the colour info. E.g:

    from termcolor import colored
    a = colored('hello', 'red')
    print(a)
    b = a[5:-4]
    print(b)