我从atom one-dark syntax中提取了以下字符串
one_dark_syn = """
@hue-1: hsl(187, 47%, 55%); // <-cyan
@hue-2: hsl(207, 82%, 66%); // <-blue
@hue-3: hsl(286, 60%, 67%); // <-purple
@hue-4: hsl( 95, 38%, 62%); // <-green
@hue-5: hsl(355, 65%, 65%); // <-red 1
@hue-5-2: hsl( 5, 48%, 51%); // <-red 2
@hue-6: hsl( 29, 54%, 61%); // <-orange 1
@hue-6-2: hsl( 39, 67%, 69%); // <-orange 2
"""我想使用python来交换十六进制的HSL值。到目前为止,我已经编写了一组看起来相当糟糕的循环,将值解析到一个numpy数组中:
od_colors = [i.split(";")[0].split(":")[1] for i in one_dark_syn.split("\n") if "hsl" in i]
od_colors = [i.strip().replace("%","").replace("hsl","").replace(" ","") for i in od_colors]
od_colors = [i.replace("(","").replace(")","").split(",") for i in od_colors]
od_colors = np.array(od_colors,dtype="int32")你看,就像我说的那样。有没有比pythonic更好的解析方式呢?最重要的是,你建议我如何将hsl转换为十六进制?
https://stackoverflow.com/questions/41403936
复制相似问题