Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想根据python中的通过或失败,将单元格的背景色设置为红色或绿色_Python - Fatal编程技术网

我想根据python中的通过或失败,将单元格的背景色设置为红色或绿色

我想根据python中的通过或失败,将单元格的背景色设置为红色或绿色,python,Python,请帮助我检查使用python更改html中单元格背景颜色的通过或失败情况 我的代码将检查几个值并返回pass和fail。现在我想让html中的pass字段变成绿色,fail字段变成红色。基本上是生成报告 代码片段 def generateReport(reportpath, dict1, dict2): html = """<html><body><table border="1"><th>FileName</th>&l

请帮助我检查使用python更改html中单元格背景颜色的通过或失败情况

我的代码将检查几个值并返回pass和fail。现在我想让html中的pass字段变成绿色,fail字段变成红色。基本上是生成报告

代码片段

def generateReport(reportpath, dict1, dict2):
        html = """<html><body><table border="1"><th>FileName</th><th>MD5</th><th>MD5</th><th><font color="red">MD5 Result</font></th><th>Sha1</th><th>Sha1</th><th><font color="red">Sha1 Result</font></th><th>Sha256</th><th>Sha256</th><th><font color="red">Sha256 Result</font></th>"""
        for key in dict1:
            if(str(dict1[key][0]==dict2[key][0])):
                status1='PASS'

            else:
                status1='FAIL'
            if(str(dict1[key][1]==dict2[key][1])):
                status2='PASS'
            else:
                status2='FAIL'
            if(str(dict1[key][2]==dict2[key][2])):
                status3='PASS'
            else:
                status3='FAIL'
html = html + "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (key,dict1[key][0],dict2[key][0],status1,dict1[key][1],dict2[key][1],status2,dict1[key][2],dict2[key][2],status3)
     html = html + "</table></body></html>"
        newhtml = open(reportpath, "w")
        newhtml.write(html)
        newhtml.close()
def GeneratorReport(报告路径、dict1、dict2): html=“”文件名MD5MD5MD5结果HA1SHA1结果HA256SHA256SHA256结果”“” 对于dict1中的键: 如果(str(dict1[key][0]==dict2[key][0]): 状态1='PASS' 其他: 状态1='FAIL' 如果(str(dict1[key][1]==dict2[key][1]): 状态2='PASS' 其他: 状态2='FAIL' 如果(str(dict1[key][2]==dict2[key][2]): 状态3='PASS' 其他: 状态3='FAIL' html=html+%s%s%s%s%s%s%s%s%s%s“%(键,dict1[键][0],dict2[键][0],状态1,dict1[键][1],dict2[键][1],状态2,dict1[键][2],dict2[键][2],状态3) html=html+“” newhtml=open(reportpath,“w”) newhtml.write(html) newhtml.close() 在上面的代码中,我面临的问题是根据状态1、状态2、状态3添加背景色

请帮帮我

谢谢
praveen.

要使表格单元格的背景为红色,可以使用
。 如果你把它和你的If声明结合起来,你应该会没事的


如果您有问题,请告诉我:)

您好,您的缩进看起来很混乱。请正确缩进代码,尤其是for循环后面的部分。