从“低色到高色调”着色HTML表格单元格。取决于Python HTML Email中的Cell Value

问题描述:

我正在使用带HTML表格的HTML-Email - Python MIME类型:text / html电子邮件,代码如下:

I am using HTML-Email with HTML Table within - Python MIME type : text/html Email with below code :

dashboardTable = """ <table>"""       
indexCount = 1
for sectionIndex in  range(0,len(sections_available)):
   dashboardTable = dashboardTable + """
      <tr>
          <td align='left'>""" + str(indexCount) + """  </td>
          <td align='left'>""" + sections_available[sectionIndex] + """  </td>
          <td align='left'> """ + str(sections_timeTaken[sectionIndex]) + """ </td>
     </tr>"""
   indexCount = indexCount + 1

dashboardTable = dashboardTable + """</table>"""

我需要为第三个单元格着色:

I need to color Third Cell:

<td align='left'> """ + str(sections_timeTaken[sectionIndex]) + """ </td>

以这种方式,最高sections_timeTaken值保持红色最低绿色 。按照从最高到最低的有序方式着色整个值范围:

In a way such that, Highest sections_timeTaken value kept with "Red Color" to lowest in "Green Color". Coloring entire range of values in ordered manner from Highest to Lowsest :

像红色 - >浅红色 - > Lightesr红色 - >黄色 - >绿色最终。[不提及确切阴影]

Like Red -> Light red -> Lightesr Red -> Yellow - > Green eventually.[ Not mentioning exact shade]

在表格中绘制的值的总数将保持动态。

The total number of Values to be plotted inside table will remain dynamic.

我在电子邮件中使用Python HTML表。

I am using Python HTML table within Email.

我认为这在HSL中更容易使用,至少在设置颜色值方面。这样你可以在0-1范围内使用每个hsl一个计数器,而不是用十六进制设置一堆点来淡出/淡出并通过数组对它们进行寻址。

I think this would be easier to work with in HSL, at least for setting up your color values. That way you can work with one counter per h-s-l in a 0-1 range versus setting up a bunch of points in hexadecimal to fade up to / down from and addressing them via an array.

幸运的是,有一个很好的用于颜色格式转换的python库:
https: //pypi.python.org/pypi/colour/0.0.5

Luckily there's a good python library for color format conversion: https://pypi.python.org/pypi/colour/0.0.5

应该很容易在我的代码中使用。

should be pretty easy to work that into your code i reckon.