Ninjaa Ninjaa - 23 days ago 6
Python Question

Color specific characters?

I'm trying to make a "Welcome message" with colors.

I'm trying to have a text like this and I would like the

$
characters to be white and all the
" | \ _ "
characters to be green

$$\ $$\
$$ | $$ |
$$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$$ |$$ __$$\ $$ | $$ |
$$ __$$ |$$$$$$$$ |$$ | $$ |
$$ | $$ |$$ ____|$$ | $$ |
$$ | $$ |\$$$$$$$\ \$$$$$$$ |
\__| \__| \_______| \____$$ |
$$\ $$ |
\$$$$$$ |
\______/


So this is what I've got so far

import sys
class color:
GREEN = '\033[92m'

print color.GREEN + """

$$\ $$\
$$ | $$ |
$$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$$ |$$ __$$\ $$ | $$ |
$$ __$$ |$$$$$$$$ |$$ | $$ |
$$ | $$ |$$ ____|$$ | $$ |
$$ | $$ |\$$$$$$$\ \$$$$$$$ |
\__| \__| \_______| \____$$ |
$$\ $$ |
\$$$$$$ |
\______/
"""


The problem is it makes everything green because of the triple quotes, I want either the dollar signs or only the other characters around it | \ / _ -

Answer

You can use string.replace to replace $ by \033[92m$\033[0m

class color:
   GREEN = '\033[92m'
   BASE = '\033[0m'

print ("""

$$\   $$\                     
$$ |  $$ |                    
$$ |  $$ | $$$$$$\  $$\   $$\ 
$$$$$$$$ |$$  __$$\ $$ |  $$ |
$$  __$$ |$$$$$$$$ |$$ |  $$ |
$$ |  $$ |$$   ____|$$ |  $$ |
$$ |  $$ |\$$$$$$$\ \$$$$$$$ |
\__|  \__| \_______| \____$$ |
                    $$\   $$ |
                    \$$$$$$  |
                     \______/ 
""".replace('$', color.GREEN + '$' + color.BASE))
Comments