Home>

I am trying:

mycolor= "240,240,240"
mycolor= webcolors.rgb_to_name ((mycolor))

But nothing comes of it.

What could be the reason?

What makes you think that nothing comes of it?

Александр2021-11-25 10:57:59
  • Answer # 1

    functionwebcolors.rgb_to_name ()expects a tuple with three integers as input, and you feed it a string as input.

    Try this:

    mycolor= (240,240,240)
    mycolor= webcolors.rgb_to_name (mycolor)
    

    If your color is initially set as string , then it can be parsed:

    from ast import literal_eval
    mycolor= "240,240,240"
    if isinstance (mycolor, str):
        mycolor= literal_eval (mycolor)
    mycolor= webcolors.rgb_to_name (mycolor)
    

    I have already tried the 1st option -it did not help ,. Thank you for your help

    Алексей Фобиус2021-11-25 11:08:30