mercredi 24 février 2021

Mime Multipart Email HTML Python | SyntaxError: 'return' outside function

I am following same procedure as this thread's accepted answer: if statement inside html email python

df_XYZ is a pandas dataframe.

HTML code:

html = """\
    <html>
      <body>
        <div>
         <table>
          <tr>
           <td >ABC</td>
           <td>&nbsp;</td>
           <td>XYZ</td>
          </tr>
          <tr>
           <td></td>
            <td></td>
            <td>
             {df1}
            </td>
           </tr>
          </table>
        </div>
      </body>
    </html>
   """

This is the if code:

if not df_XYZ.empty:
 return html.format(df1 = df_XYZ.to_html(index=False).replace('border="1"','border="0"'))
else:
 return html.format(df1 = "Some Text")

The error I get: SyntaxError: 'return' outside function

What could be the problem?

Let me know if you need any more details.

Aucun commentaire:

Enregistrer un commentaire