pythonlistcolormath

Python: how to automatically fill colormath spectral color class?


There is the SpectralColor Class in colormath.

Instead of giving manually spectral data, I want to automatically fill the class with data easily from a list, but I really don´t know how this is working.

E.g.

from colormath.color_objects import LabColor, XYZColor, SpectralColor, AdobeRGBColor
from colormath.color_conversions import convert_color

test=[0.0864521948302278, 0.060647147441089, 0.0726747188946782, 0.0939848211034762, 0.117476972460373, 0.120470421815122, 0.135515000803907, 0.147192947184837, 0.158235428114852, 0.167354983153096, 0.176595115477727, 0.184356798767392, 0.191455139493337, 0.202102699343208, 0.214077113676754, 0.225593591186178, 0.239495675347855, 0.252998713390957, 0.268988453847135, 0.286663797550772, 0.304930930121131, 0.324055045587196, 0.340413611744997, 0.35813823359423, 0.372255852167114, 0.38710860985204, 0.400396731744843, 0.411356232148721, 0.422039413253371, 0.433510097645216, 0.445295564481938, 0.455445976037395, 0.465897317024798, 0.47640303941666, 0.485959434493102, 0.49540575001133, 0.504048573672828, 0.511424852548411, 0.518111900409216]
print (test)
test2=', '.join(str(x) for x in test)
spc2=SpectralColor(test2)
xyz = convert_color(spc2, XYZColor)
print ('xyz:', xyz)

Thanks!


Solution

  • ... if someone falls into the same or similar question. You call the function differently:

    spc2=SpectralColor(*test)
    

    found in here