1

i am getting the following compilation error in the below code ,place where the error is happening is the code where the variable names are being decoded?how to decode the variable names in HTML code?

 File "test.py", line 33
    """)(% hostname,change,pwd,changeref,changeref)
         ^
SyntaxError: invalid syntax

Following is the Code:-

from email.mime.text import MIMEText
from subprocess import Popen, PIPE
import socket
import os

def email (body,subject):
    msg = MIMEText("%s" % body)
    msg["Content-Type"] = "text/html"
    msg["From"] = "[email protected]"
    msg["To"] = "[email protected]"
    msg["Subject"] = '%s' % subject
    p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
    p.communicate(msg.as_string())
def main ():
    change="2009"
    pwd=os.getcwd()
    changeref="refs/changes/59/206059/2"
    subject=change + "Test subject"
    hostname=socket.gethostname()
    body = ("""\
        <html>
         <head></head>
         <body>
          <p>%s<br>
            change - https://company/#/c/%s \n.<br>
            change Directory - %s for details \n.<br>
            Instructions: cd to the change Directory on hostname and execute the following commands \n.<br>
            git checkout %s<br>
            git fetch ssh://username@company:29418/platform/vendor/company-proprietary/code %s && git cherry-pick FETCH_HEAD".
         </p>
         </body>
        </html>
""")(% hostname,change,pwd,changeref,changeref)
    email(body,subject)

if __name__ == '__main__':
    main()
1
  • and if you can, please use new style string formatting to lose the ugliness. Commented Jan 1, 2013 at 20:09

2 Answers 2

4

What you want is

"""
your HTML stuff here
""" % (hostname, change, pwd, changeref, changeref)

Note that the % sign goes outside the tuple.

Sign up to request clarification or add additional context in comments.

Comments

0

Put the percentage sign out of the parenthesis:

         </body>
        </html>
""") % (hostname,change,pwd,changeref,changeref) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.