So forgive me a little here as im new to python just coming over from JS im having an issue running a string through a function which is meant to return a coloured text for console
File "d:\Dev\DiscordIdleBotPython\venv\ccolours.py", line 16, in colourDyn
return(f'{colours[colour]}{text}{colours["CCLEAR"]}')
~~~~~~~^^^^^^^^
TypeError: string indices must be integers, not 'str'
coloursAvailable={
"CCLEAR": '\033[0m',
"COGREEN": '\33[42m'
}
def colourDyn(text, colour):
colours=coloursAvailable[colour]
if colour not in colours: print('colour undefined or not available')
print("function passed colour check")
return(f'{colours[colour]}{text}{colours["CCLEAR"]}')
Im clearly formatting something wrong but i don’t know where perhaps im not even searching the array correctly?
any help appreciated
>Solution :
Try colours=coloursAvailable in the first line of colourDyn.
Currently, you are already getting the colour from coloursAvailable, thus the error.