Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.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
html电子邮件python中的if语句_Python_Mime - Fatal编程技术网

html电子邮件python中的if语句

html电子邮件python中的if语句,python,mime,Python,Mime,我正在使用MIME Multipart以HTML编写电子邮件,并使用smtplib发送电子邮件,并且只希望在条件计算为true时包含一个句子。基本上 html = """\ <html> <body> Hi {name}<br> Hope you are doing well. **<% if {empanelled}: %>** <br

我正在使用MIME Multipart以HTML编写电子邮件,并使用smtplib发送电子邮件,并且只希望在条件计算为true时包含一个句子。基本上

html = """\
    <html>
      <body>
        Hi {name}<br>
        Hope you are doing well.
           **<% if {empanelled}: %>**
                <br> We are already empanelled with your company<br>

      </body>
    </html>
    """.format(name=firstname, empanelled = empanelled)
html=”“”\
你好{name}
希望你做得很好。 ****
我们已经被贵公司录用了
“”格式(name=firstname,empanelled=empanelled)
如果我们是empanelled(value=1),则应写下下面的句子,否则,如果value=0,则不应出现
. 任何关于如何使用python实现这一点的建议都将不胜感激

如前所述,您应该使用以下内容。但是,除非我误解了您的问题,否则您在python中有
empanelled
变量。为什么JU不在python中对条件进行如下计算:

html = """\
    <html>
      <body>
        Hi {name}<br>
        Hope you are doing well.
             {additional_message}
      </body>
    </html>
    """

if empanelled:
    return html.format(name=firstname, additional_message="<br> We are already empanelled with your company<br>")
else:
    return html.format(name=firstname,additional_message="")
    if empanelled: 
        empanelledtxt= "<br> We are already empanelled with your company<br>"
    else:
        empanelledtxt=""
    html=html = """\
        <html>
          <body>
            Hi {name}<br>
            Hope you are doing well.""".format(name=firstname)+empanelledtxt+"""</body></html>"""`
html=”“”\
你好{name}
希望你做得很好。 {附加消息} """ 如果被任命: 返回html.format(name=firstname,附加消息=“
我们已经被贵公司录用了
”) 其他: 返回html.format(name=firstname,附加消息=”)

尽管如此,一些模板语言方法仍然会更好。

如前所述,您应该使用类似的方法。但是,除非我误解了您的问题,否则您在python中有
empanelled
变量。为什么JU不在python中对条件进行如下计算:

html = """\
    <html>
      <body>
        Hi {name}<br>
        Hope you are doing well.
             {additional_message}
      </body>
    </html>
    """

if empanelled:
    return html.format(name=firstname, additional_message="<br> We are already empanelled with your company<br>")
else:
    return html.format(name=firstname,additional_message="")
    if empanelled: 
        empanelledtxt= "<br> We are already empanelled with your company<br>"
    else:
        empanelledtxt=""
    html=html = """\
        <html>
          <body>
            Hi {name}<br>
            Hope you are doing well.""".format(name=firstname)+empanelledtxt+"""</body></html>"""`
html=”“”\
你好{name}
希望你做得很好。 {附加消息} """ 如果被任命: 返回html.format(name=firstname,附加消息=“
我们已经被贵公司录用了
”) 其他: 返回html.format(name=firstname,附加消息=”)
尽管如此,一些模板语言方法仍然会更好。

类似这样的方法:

html = """\
    <html>
      <body>
        Hi {name}<br>
        Hope you are doing well.
             {additional_message}
      </body>
    </html>
    """

if empanelled:
    return html.format(name=firstname, additional_message="<br> We are already empanelled with your company<br>")
else:
    return html.format(name=firstname,additional_message="")
    if empanelled: 
        empanelledtxt= "<br> We are already empanelled with your company<br>"
    else:
        empanelledtxt=""
    html=html = """\
        <html>
          <body>
            Hi {name}<br>
            Hope you are doing well.""".format(name=firstname)+empanelledtxt+"""</body></html>"""`
如果已启用:
empanelledText=“
我们已经被贵公司聘用了
” 其他: empanelledText=“” html=html=”“”\ 你好{name}
希望你做得很好。“.format(name=firstname)+empanelledtext+“””`
类似这样的内容:

html = """\
    <html>
      <body>
        Hi {name}<br>
        Hope you are doing well.
             {additional_message}
      </body>
    </html>
    """

if empanelled:
    return html.format(name=firstname, additional_message="<br> We are already empanelled with your company<br>")
else:
    return html.format(name=firstname,additional_message="")
    if empanelled: 
        empanelledtxt= "<br> We are already empanelled with your company<br>"
    else:
        empanelledtxt=""
    html=html = """\
        <html>
          <body>
            Hi {name}<br>
            Hope you are doing well.""".format(name=firstname)+empanelledtxt+"""</body></html>"""`
如果已启用:
empanelledText=“
我们已经被贵公司聘用了
” 其他: empanelledText=“” html=html=”“”\ 你好{name}
希望你做得很好。“.format(name=firstname)+empanelledtext+“””`
是否
empanelled
是Python变量?您应该使用适当的模板解决方案,例如Jinja2。是的,empanelled是Python变量是
empanelled
是Python变量?您应该使用适当的模板解决方案,例如Jinja2。是的,empanelled是Python变量感谢这些解决方案和指针。这巧妙地解决了它:)太棒了@AdityaGanguli如果答案对你有效,请接受!感谢您提供的解决方案和建议。这巧妙地解决了它:)太棒了@AdityaGanguli如果答案对你有效,请接受!谢谢你的快速回复。使用了与您的答案类似的内容。感谢您的快速回复。使用了与你的答案相似的东西。