0
a, b = "\033[0;37m hi", "\033[0;36m hi"

if a == b:
  print('hi')
else:
  print('bye')

Can you ignore the coloring in the if statement to make it print hi?

aid6n
  • 1
  • 1
  • https://stackoverflow.com/q/14693701/202168 – Anentropic May 09 '22 at 15:44
  • Does this answer your question: https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python – ex4 May 09 '22 at 15:44
  • Does this answer your question? [How can I remove the ANSI escape sequences from a string in python](https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python) – Banana May 09 '22 at 15:49
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 09 '22 at 21:27

1 Answers1

1

You can do that easily by splitting these two strings for example:

a, b = "\033[0;37m hi", "\033[0;36m hi"

if a.split(' ')[1] == b.split(' ')[1]:
  print('hi')
else:
  print('bye')

I recommend this way I find it more elegant and easy

#add this class to your file

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    #you can add more colors here

How to use

a = "Hi"
print(f"{bcolors.OKGREEN}", a , f"{bcolors.ENDC}")

Now you can compare two strings normally

amd
  • 342
  • 1
  • 2
  • 15